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 :)
- #include<iostream.h>
- #include<conio.h>
- void main()
- {
- clrscr();
- int n,sum=0;
- cout<<"Please enter a number: ";
- cin>>n;
- for (int i=1;i<=n;i++)
- //Coding by: Snehil Khanor
- //http://WapCPP.blogspot.com
- {
- if(i%2!=0)
- sum=sum+i;
- else
- continue;
- }
- cout<<sum;
- getch();
- }
1 comments:
C++ Program Even and Odd Elements in Array
oh, great
Post a Comment