Pages

This blog is under construction

Thursday, December 20, 2018

C program to read a four digit integer and print the sum of its digits.

#include<stdio.h>
void main()
{
   int Num,Sum=0,Digit;
   printf("Enter a Four Digits Number\n",&Num);
   scanf("%d",&Num);
   Digit=Num%10;
   Num=Num/10;
   Sum+=Digit;

   Digit=Num%10;
    Num=Num/10;
   Sum+=Digit;

   Digit=Num%10;
   Num=Num/10;
   Sum+=Digit;

   Digit=Num%10;
   Num=Num/10;
   Sum+=Digit;
   printf("\nSum of Digits are :-- %d\n",Sum);
}


Enter a Four Digits Number                                                                                                                           
1245                                                                                                                                                 
                                                                                                                                                     
Sum of Digits are :-- 12 

No comments:

Post a Comment