Advertisement
samrina_sarkar_7

Odd number and its sum

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