Program to input three number and print their sum of digits in C.

In this program we input three numbers and print their sum of digit. First we find 1st digit by (n/100), 2nd digit by(n/10)%10 and 3rd digit by (n%10). Then finally sum of digits.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,d1,d2,d3,s=0;
clrscr();
printf("Enter three digit number=");
scanf("%d",&n);
d1=(n/100);
d2=(n/10)%10;
d3=n%10;
s=d1+d2+d3;
printf("\nSum of digits=%d",s);
getch();
}

OUTPUT 


Comments

Popular posts from this blog

Write a program to input a number and check number is negative or not.

Write a program to input age of any person and check he is eligible for voting or not.