write a c++ program to find the sum of first 10 odd numbers
Answers
Answered by
3
Answer:
#include<iostream>
using namespace std;
int main()
{
///variable declaration
int arr[20];
int n;
int sum_odd=0,sum_even=0;
cout<<"enter the size of the array:";
cin>>n;
for(int i=0; i<=n; i++)
{
if(i%2!=0)
{
sum_odd = sum_odd+i;
}
if(i%2==0)
{
sum_even = sum_even+i;
}
}
cout<<"sum of 10 odd numbers:"<<sum_odd;
cout<<"sum of 10 even numbers:"<<sum_even;
return 0;
}
Explanation:
Similar questions
Social Sciences,
6 months ago
Computer Science,
6 months ago
English,
6 months ago
Math,
1 year ago
Science,
1 year ago
History,
1 year ago
Computer Science,
1 year ago