Maplewing

5/14 C: Function: sum

May 13th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int sum(int n){
  4.     int total = 0;
  5.     int i;
  6.     for( i = 1 ; i <= n ; i++ ){
  7.         total += i;
  8.     }
  9.    
  10.     return total;
  11. }
  12.  
  13.  
  14. int main(){
  15.     int a, b;
  16.     scanf("%d%d", &a, &b);
  17.    
  18.     //int sumA = sum(a);
  19.     // int sumA = sum(10) + 8 * 6;
  20.     // int sumA = 55 + 8 * 6;
  21.    
  22.     //int sumB = sum(b);
  23.    
  24.     printf("sumA: %d\n", sum(a));
  25.     printf("sumB: %d\n", sum(b));
  26.    
  27.     return 0;
  28. }
Add Comment
Please, Sign In to add comment