Professional Documents
Culture Documents
Write C Programs For The Following
Write C Programs For The Following
Write C Programs For The Following
b) If a five-digit number is input through the keyboard, write a program to calculate the sum
of its digits. (Hint: Use the modulus operator ‘%’)
#include<stdio.h>
int main()
{ int x,a,b,c,d,e,p,q,r;
printf(" Enter a 5-digit number : ");
scanf("%d",&x);
a=x/10000;
p=x%10000;
b=p/1000;
q=p%1000;
c=q/100;
r=q%100;
d=r/10;
e=r%10;
printf("\n Sum of its digits : %d",a+b+c+d+e);
}
c) If a five-digit number is input through the keyboard, write a program to print a new
number by adding one to each of its digits. For example if the number that is input is 12391
then the output should be displayed as 23402.
#include<stdio.h>
int main()
{ int x,a,b,c,d,e,p,q,r;
printf(" Enter a 5-digit number : ");
scanf("%d",&x);
a=x/10000;
p=x%10000;
b=p/1000;
q=p%1000;
c=q/100;
r=q%100;
d=r/10;
e=r%10;
printf("\n New No. : %d",a+1,b+1,c+1,d+1,e+1);
}
d) If a four-digit number is input through the keyboard, write a program to obtain the sum of
the first and last digit of this number.
#include<stdio.h>
int main()
{ int x,a,b,c,d,p,q;
printf(" Enter a 5-digit number : ");
scanf("%d",&x);
a=x/1000;
p=x%1000;
b=p/100;
q=p%100;
c=q/10;
d=q%10;
printf("\n Sum of first and last digit : %d",a+e);
}
e) In a town, the percentage of men is 52. The percentage of total literacy is 48. If total
percentage of literate men is 35 of the total population, write a program to find the total
number of illiterate men and women if the population of the town is 80,000.
#include<stdio.h>
int main()
{ float x,y,z,a,b,c,d;
printf(" enter total population :");
scanf("%f",&x);
y=0.52*x;
z=0.48*x;
a=0.35*y;
b=0.13*z;
c=y-a;
d=z-b;
printf("\n no of ill men :%f",c);
printf("\n no of ill women :%f",d); }