adding digits of a number in c
//program to find the sum of digits:
#include<stdio.h>
int main()
{
int num,sum=0,r,temp;
printf("Enter the number:\n "); //taking input from the user
scanf("%d",&num);
temp=num; //assigning num to temporary variable
while(temp!=0)
{
r=temp%10;
sum=sum+r;
temp=temp/10;
}
printf("\nGiven number = %d",num);
printf("\nSum of the digits = %d",sum);
}
//code By dungriyalEnter the number
300
Given number = 300
Sum of the digits 300 = 3
Enter the number
16789
Given number = 16789
Sum of the digits 16789 = 31
Also in C:
- objective c swizzle method
- malloc syntax
- ImportError: No module named 'skimage'
- a enum data type in c
- c shift array left
- animation with c
- how to print the elements of a linked list in c
- c get first n characters of string
- how to add user to role postgresql
- c check if file was created
- how to change file permissions in C language
- C printf to string
- how to combine strings in c
- how to login to docker inside kubernetes cluster
- c isdigit function
- #pragma pack(1) in c
- porn
- vue cdn
- how to transfer textbox fro string to integer vb.net
- how to find the ith row of pascal's triangle in c
- how to get a lonng in scanf in c
- error 403
- calloc
- merge sort in c