Pages

Ads 468x60px

Saturday, 2 June 2012

C Program For SUM OF DIGITS


C Program For SUM OF DIGITS



This code simply first inputs two values and stores them in integer variables 
num1 , num2 , finds their sum and stores in variable sum and then prints the 
value of sum as the sum of two number given by users.





CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,t,s=0;
clrscr();
printf("Enter the digit");
scanf("%d",&n);
while(n>0)
{
t=n%10;
s=s+t;
n=n/10;
}
printf("sum =%d",s);
getch();
}

0 comments:

Post a Comment

Total Pageviews