Advertisement
PROFESSOR_AIH

Sum of Consecutive Odd Numbers I

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