C Program to Count Number of Digits in an Integer - IProgramX

Q. Write a program to accept an integer and count the number of digits in the number and sum of digit


Program 

#include<stdio.h>
int main()
{
int a,j=0,p,sum=0;
printf("enter the no : ");
scanf("%d",&a);
while(a!=0)
{
p=a%10;
a=a/10;
j++;
sum=sum+p;
}
printf("digit= %d and sum= %d",j,sum);
}

Output:

enter the no : 4532
digit= 4 and sum= 14

Post a Comment

0 Comments