Template by:
Free Blog Templates

Saturday, November 7, 2009

Add digits of 3 digit no C programming

//wap to add digits of any 3 digit no
#include
#include
void main()
{int i,n,r,sum=0;
clrscr();
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
for(i=1;i<=3;i++)
{
r=n%10;
sum=sum+r;
n=n%10;
}
printf(“\n\n\a\tThe sum is :%d”,sum);
getch();
}

o/p→
enter a number : 123
The sum is : 6



0 comments:

Post a Comment

If you have any proble fee free to ask it here