Advertisement
Mahmud33

sum of all odd numbers between 1 to n

Jun 30th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.23 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int i, n, sum=0;
  6.  
  7.     printf("n = ");
  8.     scanf("%d", &n);
  9.  
  10.     for(i=1; i<=n; i+=2)
  11.     {
  12.         sum += i;
  13.     }
  14.  
  15.     printf("Sum of odd numbers = %d", sum);
  16.  
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement