0
In c++ sum of first 20 odd numbers what is codding
what is codding
2 Respuestas
+ 2
int sum = 0;
for (int i = 0, j = 1; i < 20; i++, j += 2)
sum += j;
0
#include<iostream>
using namespace std;
int main()
{
int oddSum =0;
int i =1,j=0;
while(j<20)
{
if(i%2==1){
oddSum += i;
j++;
}
i++;
}
cout<<"Sum of first 20 odd number is "<<oddSum;
return 0;
}