• Uncategorized

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...


Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 9

Warning: Attempt to read property "cat_name" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 9

Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 14

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

Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 15

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