0

In c++ sum of first 20 odd numbers what is codding

what is codding

11th Mar 2017, 8:15 AM
pooja patl
2 Antworten
+ 2
int sum = 0; for (int i = 0, j = 1; i < 20; i++, j += 2) sum += j;
11th Mar 2017, 8:30 AM
AtoMX
AtoMX - avatar
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; }
11th Mar 2017, 8:34 AM
ram dhas
ram dhas - avatar