Code Box
--------------------------------------------
/*Program to find sum of digits of any number given by user max. 5 digits */
#include<stdio.h>
#include<conio.h>
void main()
{
int num,num1,rem,sum,i;
clrscr();
sum=0;
printf("\n\tSum of Digits Finder");
printf("\n-------------------------");
printf("\nEnter a number:");
scanf("%d",&num);
num1=num; //to save actual number
while(num1>=1)
{
rem=num1%10;
num1=num1/10;
sum=sum+rem;
}
printf("\nSum of all digits = %d",sum);
getch();
}
No comments:
Post a Comment