rabbinur

Sample C Program To Print Sum Of Series 1 + 3 + 5 + …. N.

Aug 14th, 2012
42
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. #include <conio.h>
  3. void main()
  4. {
  5.  
  6. int n, i, sum = 0;
  7. clrscr();
  8.  
  9. printf(" Enter any number: " );
  10. scanf(" %d ", &n);
  11.  
  12. for(i = 1; i<n; i = i + 2 )
  13. {
  14. printf(" %d + ", i);
  15. sum = sum + i;
  16. }
  17. printf(" %d ", n);
  18. printf(" \nSum = %d ", sum + n );
  19. getch();
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment