C Program to input 4 integer number and calculate the sum of digits in the given number

Now we are going to see how the digits of the given number are calculated in C. Following code illustrates the process involved using the arithmetic operators.

//Program to input 4 digit integer number and calculate the sum of digits
#include<stdio.h>
int main(){
	int r1, r2, r3,n,sum;
	printf("Enter any four digits number");
	scanf("%d",&n);
	r1=n%10;
	n=n/10;
	r2=n%10;
	n=n/10;
	r3=n%10;
	n=n/10;
	sum=r1+r2+r3+n;
	printf("Sum of digits= %d", sum);
}

The result of the program above will be displayed as in the picture below.

SHARE C Program to input 4 integer number and calculate the sum of digits in the given number

You may also like...

Leave a Reply

Your email address will not be published.


Warning: Undefined variable $category in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/sidebar_tutorial.php on line 10

Warning: Trying to access array offset on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/sidebar_tutorial.php on line 10

Warning: Attempt to read property "category_parent" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/sidebar_tutorial.php on line 10
Share