Thursday 15 March 2012


TO DISPLAY THE SUM OF INDIVIDAL DIGITS OF A FOUR DIGIT NUMBER




To accept a four digit number and to display the sum of individual digits
#include<stdio.h>
Viod main()
{
Int number,temp,d1,d2,d3,d4,sum;
Clrscr();
Printf(“enter a number”;
Scanf(“%d”,&number);
Temp=number;
D4=number/1000;
Number=number%1000;
D3=number/100;
Number=number%100;
D2=number/10;
D1=number%10;
Sum=d4+d3+d2+d1;
Printf(“sum of individual digits of %d is %d”,temp sum);
Getch();
}

No comments:

Post a Comment