Description:
This program automatically calculate sum of first ten odd numbers using 'for' loop.
Code:
This program automatically calculate sum of first ten odd numbers using 'for' loop.
Code:
#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
int i,j,s=0;
i=1;
cout<<"The first ten odd numbers are"<<endl;
while(i<20)
{
if(i%2!=0)
{
cout<<i<<" ";
s=s+i;
}
i++;
}
cout<<endl<<"The sum of first ten odd numbers is"<<endl<<s;
getche();
return 0;
}
No comments:
Post a Comment