Differentiate and add the digits of three digit number
Here, the code of differentiate and add the digits of a three-digit number entered by the user.
Code:
//The task is to add the digits of three digit number ,that is input by the user.
#include <stdio.h>
int main()
{
int a, b, c, d, e, sum = 0; //variable declaration
printf("Enter a three digit number:");
scanf("%d", &a); // The user input the 3 digit number
b = a / 100; //first digit
c = a % 100; //last 2 digits
d = c / 10; //middle digit
e = c % 10; //last digit
sum = b + d + e;
printf("\nThe indvidual digits are : %d\t%d\t%d", b, d, e);
printf("\nThe sum is :%d\n", sum); //sum of 3 digits will appear on screen.
getchar;
return 0;
}
Comments
Post a Comment