Monday, 6 July 2015

Write C Program To Perform Inputed Degits Summation

Write C Program To Perform Inputed Degits Summation
1:  int main()  
2:  {  
3:    int n, t, sum = 0, remainder;  
4:    printf("Enter an integer");  
5:    scanf("%d", &n);  
6:    t = n;  
7:    while (t != 0)  
8:    {  
9:     remainder = t % 10;  
10:     sum    = sum + remainder;  
11:     t     = t / 10;  
12:    }  
13:    printf("Sum of digits of %d = %d", n, sum);  
14:    return 0;  
15:  }  

No comments:

Post a Comment