Professional Documents
Culture Documents
Sum of Even Nos
Sum of Even Nos
#include<iostream.h> #include<conio.h> void main() { int i,sum=0,sqsum=0; clrscr(); for(i=1;i<31;i++) { if(i%2==0) {sum+=i; sqsum+=(i*i); } } cout<<"sum of first 15 even no.="<<sum; cout<<"\n and sum of their squares="<<sqsum; getch(); }
output
sum of first 15 even no.=240 and sum of their squares=4960