Ad

Chapter - 2: C Instructions

If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. (Hint: Use the modulus operator '%')


Ad
H
Sections
1
Exercises
#include<stdio.h>
#include<conio.h>
int main()
{
	int num,a,b,c,d,e;
	printf("Enter a five digit number : ");
	scanf("%d", &num);
	e=num%10;
	d=(num/10)%10;
	c=(num/100)%10;
	b=(num/1000)%10;
	a=(num/10000);
	printf("%d is the sum of the digits of the number %d.", a+b+c+d+e, num);
	getch();
	return 0;
}
Ad

© 2024 Garbage Valuegarbage value logo