Sunday, 11 December 2011

Write a program to print sum of given digits by user in c

#include
#include
void main()
{
int n, p=0,s,x=1,ct=0,sum=0;
clrscr();
printf("Enter The Number:");
scanf("%d",&n);
while(ct0)
{
p=(p*10)+(s%10);
s=s/10;
}
if(x==p)
{
sum=sum+x;
ct++;
}
x++;
}
printf("sum is: %d",sum);
getch();
}



OUTPUT

Enter The Number : 6
Sum is : 21

No comments:

Post a Comment