Thursday, March 3, 2016

Sum of a number's components in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>

main()
{
 int i,sum,sum1=0,sum2=0, sum3=0, sum4=0;
 
 {
  scanf("%d",&i);
  sum1=i%10;
  i=i/10;
  sum2=i%10;
  i=i/10;
  sum3=i%10;
  i=i/10;
  sum4=i%10;
  i=i/10;
 }
 sum= sum1+sum2+sum3+sum4;
 printf("%d\n",sum);
 
}

No comments:

Post a Comment

Thank you for commenting. Please wait for response :)