Q:

Write a program to calculation of sum of the digit

0

Write a program to calculation of sum of the digit

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,sum=0;
printf("enter a number\n");
scanf("%d",&n);
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("sum of digit of entered number %d",sum);
getch();
}

Output:

enter a number
420
sum of digit of entered number 6

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Programming Exercises With Solutions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a program to reverse a string without using ... >>
<< Write a program to demonstrate print to increament...