AdvC DA Mod PDF
AdvC DA Mod PDF
Print the
message “good”
#include <stdio.h>
int main()
{
float n;
printf("enter a number: ");
scanf("%f",&n);
if(n<=10)
{
printf("GOOD");
}
return 0;
#include <stdio.h>
int main()
{
char l;
printf("enter a letter ");
scanf("%c",&l);
if(l>='A' && l<='Z' || l>='a' && l<='z')
{
if (l=='a'||l=='e'||l=='i'||l=='o'||l=='u'||l=='A'||l=='E'||l=='I'||l=='O'||l=='U')
{
printf("its a VOWEL \n");
}
else
{
printf("its a CONSONANT \n");
}
}
else{ printf("different character..."); }
return 0;
}
3. Read three numbers from the user and find the biggest of three using
simple (multiple) if statements.
#include <stdio.h>
int main()
{
int n1,n2,n3;
printf("enter three numbers..");
scanf("%d%d%d",&n1,&n2,&n3);
if(n1>n2)
{
if(n1>n3)
{
printf("n1 is the biggest number %d",n1);
}
If(n1<n3)
{
printf("n3 is the biggest number %d",n3);
}
}
if(n2>n3)
{
printf("n2 is the biggest number %d",n2);
}
If(n3>n2)
{
printf("n3 is the biggest no. %d",n3);
}
return 0;
}
#include <stdio.h>
int main()
{
int year;
printf("enter the year to see if its a leap year");
scanf("%d",&year);
if(year%4==0 && year%100!=0)
{
printf("its leap year...:%d",year);
}
else
{
printf("not a leap year");
}
return 0;
}
#include<stdio.h>
int main()
{
float n;
printf("enter data: ");
scanf("%f",&n);
if(n<5.0)
{
printf("little or no damage");
}
else if(n>=5.0 && n<5.5)
{
printf("some damage");
}
else if(n>=5.5 && n<6.5)
{
printf("serious damage");
}
else if(n>=6.5 && n<7.5)
{
printf("disaster");
}
else
printf("Higher Catastrophe");
}
#include <stdio.h>
int main()
{
int n,temp,rem,rev=0;
printf("enter a number to check if its palindrome!");
scanf("%d",&n);
temp=n;
while(n!=0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
if(temp==rev)
{
printf("its palindrome!!");
}
else
{
printf("NOT palindrome...");
}
return 0;
}
7. Write a c program to check given number is Armstrong number or not.
#include<stdio.h>
#include<math.h>
int main()
{
int n,rem,sum=0,temp;
printf("enter a number to check if its armstrong");
scanf("%d",&n);
temp=n;
while(n>0)
{
rem=n%10;
sum=sum+pow(rem,3);
n=n/10;
}
if(temp==sum)
printf("armstrong");
else
printf("its NOT armstrong");
return 0;
}
8. Write a C program to convert a binary number to decimal number.
#include<stdio.h>
void main()
{
int num, bin, dec= 0, base = 1, rem;
printf("Enter a binary number \n");
scanf("%d", &num);
bin= num;
while (num > 0)
{
rem = num % 10;
dec= dec + rem * base;
num = num / 10 ;
base = base * 2;
}
printf("The Binary number is = %d \n", bin);
printf("Its decimal equivalent is = %d \n", dec);
}
9. Write a C program to find out the sum of series 1^2 + 2^2 + …. + n^2
#include<stdio.h>
int main()
{
int n,i,sum=0;
printf("enter the number n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+(i*i);
}
printf("the sum of the series:\n 1^2 + 2^2 + …. + n^2 = %d",sum);
return 0;
}
10. Write a C program to read the age of 100 persons and count the
number of persons in the age group 50 to 60. Use for and continue
statement
#include<stdio.h>
int main()
{
int age[100],count=0;
printf("enter the age of people:");
for(int i=0;i<100;i++)
{
scanf("%d",&age[i]);
}
for(int i=0;i<100;i++)
{
if(age[i]>=50 && age[i]<=60)
{
count++;
}
else
continue;
}
printf("Number of people with age group 50-60 years: %d",count);
return 0;
}
11. Write a C program to calculate and print the sum of first 5 terms of
following: /1+ (1+2) + (1+2+3) + (1+2+3+4) +…
#include<stdio.h>
int main()
{
int sum=0,n,i,j;
printf("to find sum of series: 1+(1+2)+(1+2+3)+(1+2+3+4)+..");
printf("take n from user: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
sum=sum+j;
}
}
printf("the sum of series is= %d",sum);
return 0;
}
#include<stdio.h>
int main(){
int i,j,k=1;
for(i=1;i<=4;i++){
for(j=1;j<=i;j++)
{ printf("%d\
t",k); k++;
}
printf("\n");
return 0;
13. Write a program to read 3 digit numbers and print the digits in
words using switch case
#include<stdio.h>
#include<ctype.h>
int main()
{
int n,num,a=100,b=100;
printf("enter a 3 digit no:");
scanf("%d",&n);
for(int i=0;i<3;i++)
{
num=n/a;
switch(num)
{
case 0:
printf("zero ");
break;
case 1:
printf("one ");
break;
case 2:
printf("two ");
break;
case 3:
printf("three ");
break;
case 4:
printf("four ");
break;
case 5:
printf("five ");
break;
case 6:
printf("six ");
break;
case 7:
printf("seven ");
break;
case 8:
printf("eight ");
break;
case 9:
printf("nine ");
break;
}
a=a/10;
n=n%b;
b=b/10;
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char str[50];
int count;
count=0;
printf("enter the string to search for vowels");
gets(str);
for(int i=0;i<strlen(str);i++)
{
switch(str[i])
{
case 'a':
count++;
break;
case 'e':
count++;
break;
case 'i':
count++;
break;
case 'o':
count++;
break;
case 'u':
count++;
break;
case 'A':
count++;
break;
case 'E':
count++;
break;
case 'I':
count++;
break;
case 'O':
count++;
break;
case 'U':
count++;
break;
}
}
if(count>0)
printf("no of VOWELS: %d",count);
else
printf("no vowels are present!!!");
return 0;
}
#include<math.h>
#include<ctype.h>
int main()
int b;
float num;
char ans;
scanf("%f",&num);
do{
scanf("%d", &b);
switch(b)
break;
break;
break;
break;
break;
break;
break;
}
printf("\nDo you want to continue?\n");
fflush(stdin);
scanf("%c",&ans);
if(ans=='n')
else if(ans!='y'&&ans!='n')
return 0;
}
17. Write a C Program to read student’s grade from keyboard from 1 to 5)
and prints it’s description.1.Fail 2.Bad 3.Good 4.VeryGood 5.Excellent
,default: false grade
#include<stdio.h>
int main()
{
char grade;
printf("enter your grade =");
scanf("%c",&grade);
if(isalpha(grade)==0)
printf("enter in alphabets!");
switch(grade)
{
case 'a':
printf("excellent");
break;
case 'b':
printf("very good");
break;
case 'c':
printf("good");
break;
case 'd':
printf("bad");
break;
case 'f':
printf("FAIL");
break;
default:
printf("false grade");
}
return 0;
}
18. Get a single digit number from the user (0-9) one after another, until the
user wishes. Finally display the count of each numbers and display it using
switch and goto.
#include<stdio.h>
#include<string.h>
int main()
char ans;
int num;
lable :
switch(num)
default:;
scanf(" %c",&ans);
if(ans=='y')
{ goto
lable;
else if(ans=='n'){
else
return 0;}
Challenging C Programs
#include<stdio.h>
int main()
{
int i,j=122,newline=1;
for(i=97;i<=122;i++)
{
printf("%c%c ",i,j);
if(newline==9||newline==18)
printf("\n");
j--;
newline++;
}
return 0;
}
int main()
int n;
printf("enter n: ");
scanf("%d",&n);
float sum = 1;
int fact = 1;
fact *= i;
sum += 1.0/fact;
printf("%f",sum);
return 0;
#include<conio.h>
#include<math.h>
double f=1;
int k;
for(k=1;k<=power;k++)
f=f*k;
return f;
void main()
int i=1;
double x,term,deno,lob,sin,power=3;
scanf("%lf",&x);
x=3.142/180*x;
term=x;
sin=x;
while(term>=0.0001)
lob=pow(x,power);
deno=fact(power);
term=lob/deno;
power+=2; if(i
%2==1)
sin=sin-term;
else
sin=sin+term;
i++;
4. Write a C program, for all positive integers i,j,k, and l from 1 through 50,
finds and /prints all combinations of i,j,k and l such that i+j+k=l and i < j < k <
l.
#include<stdio.h>
int main()
{
int i,j,k,l;
for(l=1;l<=50;l++)
for(k=1;k<l;k++)
for(j=1;j<k;j++)
for(i=1;i<j;i++)
{
if((i+j+k)==l) printf("%d+%d+%d=
%d \n",i,j,k,l);
}
return 0;
}
5. Write a C program to print all integers that are not divisible by 2 or 3 and
lie between 1 and 100. Program should also account /the number of such
integers and print the result
#include<stdio.h>
int main()
{
int i,count=0,sum=0;
for(i=1;i<=100;i++)
{
if(((i%2)!=0) || ((i%3)!=0))
{
count++;
printf("%d \n",i);
}
}
printf("the count= %d",count);
return 0;
}
#include<stdio.h>
int main()
{
signed int n[100];
int i,sum=0;
for(i=1;i<=10;i++)
{
scanf("%d",&n[i]);
if(n[i]>0)
{
sum=sum+n[i];
}
}
if(sum>=999)
printf("the sum exeeds 999");
else
printf("%d",sum);
return 0;
}
7. The equation x2+y2 = r2 represents a circle with center at origin and radius
r. Write a C program that reads r from the keyboard and prints the number of
points with integer coordinated that lie within the circle
#include<stdio.h>
#include<math.h>
void main()
float r,dist;
scanf("%f",&r);
int c=0;
for(int i=0;i<r;i++)
for(int j=0;j<r;j++)
continue;
dist=sqrt(pow(i,2)+pow(j,2));
if(dist<r)
c++;
}
#include <stdio.h>
#include
<string.h>
#include <ctype.h>
int main()
char n[100],c=0;
scanf("%s", n);
for(int i=0;i<strlen(n);i++)
if(isdigit(n[i]))
c=1;
else{
printf("invalid input");
c=0;
break;
}
if(c==1){
for(int i=0;i<strlen(n);i++)
switch(n[i])
case '0':
printf("zero ");
break;
case '1':
printf("one ");
break;
case '2':
printf("two ");
break;
case '3':
printf("three ");
break;
case '4':
printf("four ");
break;
case '5':
printf("five ");
break;
case '6':
printf("six ");
break;
case '7':
printf("seven ");
break;
case '8':
printf("eight ");
break;
case '9':
printf("nine ");
break;
return 0;
}}
#include<stdio.h>
void main(){
int base=25000,tot;
{ for(int b=0;b<=1;b+
+){
for(int c=0;c<=1;c++)
{ tot=base+a*85+b*25+c*30
0;
printf("%d %d %d %d %d\n",base,a,b,c,tot);
Additional C Programs
19. Write a program to print all possible combinations of the digit 2, 5 and 7
using for loop only
#include<stdio.h>
int main()
int a[3]={2,5,7};
int i,j,k,m;
for(i=0;i<3;i++)
{ for(j=0;j<3;j++){
for(k=0;k<3;k++){
{ m=(100*a[i])+(10*a[j])
+a[k];
printf("%d \n",m);
return 0;
#include<stdio.h>
int main(){
float i,y,x;
for(y=1;y<=6;y++){
for(x=5.5;x<=12.5;x+=0.5){
i=2+(y+(0.5)*x);
return 0;
21. Write a menu driven c program with the following options 1. odd or even
2. Prime or not 3. Factorial of a number 4. Exit
#include<stdio.h>
void oddeven()
int x;
scanf("%d",&x);
if(x%2==0)
printf("it is even");
else
printf("it is odd");
void prime()
int num,i,ctr=0;
scanf("%d",&num);
for(i=2;i<=num/2;i++){
if(num % i==0){
ctr++;
break;
else
void fact()
int i,j,n,fac=1;
scanf("%d",&n);
for(i=n;i>0;i--)
fac=fac*i;
printf("factorial is %d",fac);
int main(){
int ch;
do{
printf("\n enter your choice: 1.odd and even 2.prime or not 3.factorial of a number 4.exit\n");
scanf("%d",&ch);
switch(ch)
{ case
1:oddeven();
break;
case 2:prime();
break;
case 3:fact();
break;
case 4:break;
default:printf("wrong choice!!!!!!!!!!!!!");
break;
}while(ch!=4);
return 0;
#include<stdio.h>
int main()
float sum=0.0;
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++)
float fac=1,fac2;
for(j=1;j<=i;j++)
fac=fac*j;
fac2=fac*(j+1);
sum=sum+(fac/fac2);
return 0;
23. Write a C program to swap two given numbers with and without using
the third variable (Hint: using bitwise operators (ex-or ^), using + and -, using
* and / (without using third variable)
#include<stdio.h>
int main(){
int a,b,c,ch;
printf("if you want to swap using two variables enter 1 \n if you want to swap using three variables
enter 2");
scanf("%d",&ch);
if(ch==1){
scanf("%d %d",&a,&b);
a=a+b; //alternate:a=a*b;
b=a-b; // alternate:b=a/b;
a=a-b; // alternate:a=a/b;
else if(ch==2){
scanf("%d %d",&a,&b);
c=a;
a=b;
b=c;
else
printf("wrong choice");
return 0;