Program for calculating Sum of Digits of a given Number

#include<stdio.h> #include<conio.h> main (  ) { int n, s,n,r ; 0; printf (“enter a number”); scanf (“%d”, &n); ...

#include<stdio.h>
#include<conio.h>
main (  )
{
int n, s,n,r ; 0;
printf (“enter a number”);
scanf (“%d”, &n);
while (n! = 0)
{
r = n% 10;
s = r + s;
n = n/10;
printf (“sum of digits is % d”, r);
}
getch();
}

Out Put:

Enter a number 567
Sum of digits is 18

Related

C Programs 3769385256039893529

Post a Comment

emo-but-icon

item