Write a program to input any no. count it's digits after that print no. of digits and sum of digits.
Code Written in Dev C++;
#include<stdio.h>
#include<conio.h>
int main()
{
int n, c=0, s=0, a;
printf("\nEnter any no.:-");
scanf("%d",&n);
while(n>0)
{
a=n%10;
s=s+a;
c=c+1;
n=n/10;
}
printf("\n Number of digits in given no. is %d.",c);
printf("\n Sum of digits of given no. is %d.",s);
return 0;
}
Code Written in Turbo C++ :-
#include<stdio.h>
#include<conio.h>
void main()
{
int n, c=0, s=0, a;
clrscr();
printf("\nEnter any no.:-");
scanf("%d",&n);
while(n>0)
{
a=n%10;
s=s+a;
c=c+1;
n=n/10;
}
printf("\n Number of digits in given no. is %d.",c);
printf("\n Sum of digits of given no. is %d.",s);
getch();
}
0 Comments