Q11.
Write a C program to read a number from the keyboard and to add each of its digits.
[Hint:
void main( )
{
int r, sum=0, num;
printf(“Enter a number:”);
scanf(“%d”, &num);
while(num > 0)
{
r = num % 10;
sum = sum + r;
num = num /10;
}
printf(“The sum of digits is= %d”, sum);
}
}
Do'stlaringiz bilan baham: