Thursday 3 October 2013

Adding digits of a number using C

#include<stdio.h>
main()
{
int num,rem,sum=0,temp;
printf("\n(There is) none worthy of worship except Allah(Subhanahu wa ta'ala).Muhammad(Sallallahu alayhi wasallam) is Messenger of ALLAH(Subhanahu wa ta'ala).\n");
printf("Enter the number: ");
scanf("%d",&num);
temp=num;
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf("Sum of the digits of %d is %d\n",temp,sum);
}

No comments:

Post a Comment