Advertisement
Nabil-Ahmed

Untitled

Jul 5th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. //display the n terms of odd natural number and their sum//
  2. #include <stdio.h>
  3. int main()
  4. {
  5.    int i,n,sum=0;
  6.  
  7.    printf("Input number of terms : ");
  8.  
  9.    scanf("%d",&n);
  10.  
  11.    printf("\nThe odd numbers are :");
  12.  
  13.    for(i=1;i<=n;i++)
  14.    {
  15.      printf("%d ",2*i-1);
  16.      sum+=2*i-1;
  17.    }
  18.  
  19.    printf("\nThe Sum of odd Natural Number upto %d terms : %d \n",n,sum);
  20.    return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement