Wednesday, 28 August 2013

If a five digit number is input through the keyboard, write a program to calculate the sum of its digits.

#include<stdio.h>
void main()
{
int a[5],t=0,i,n;
printf("enter a no");
scanf("%d",&n);
for(i=0;i<5;i++)
{
a[i]=n%10;
t=t+a[i];
n=n/10;
}
printf("five digit no total is:%d\n",t);
}

No comments:

Post a Comment