W.A.P. C++

WAP | CPP | Programs in C++ | C++ Solutions

Snehil Khanor's Binary Log

write a program to calculate sum of all odd numbers upto n


A number n is taken from user and sum of all odd numbers upto n is calculated.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,sum=0;
  7. cout<<"Please enter a number: ";
  8. cin>>n;
  9. for (int i=1;i<=n;i++)
  10. //Coding by: Snehil Khanor
  11. //http://WapCPP.blogspot.com
  12. {
  13. if(i%2!=0)
  14. sum=sum+i;
  15. else
  16. continue;
  17. }
  18. cout<<sum;
  19. getch();
  20. }

Search

About WAP C++

Here you'll find a wide range of programs' solution ranging from beginer level to advanced level.
All programs here are made, compiled and tested by me..and are running absolutely fine.. still if you find any bug in any program do let me know :)

Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner

my Binary Log

Blog Archive



eXTReMe Tracker