//------------------------------------------------- // Jordi Binefa i Martínez // dubtes@excite.com // http://members.juara.com/asi //------------------------------------------------- //Write the program DOWHILE2.CPP, that uses a loop //("do-while" type) to get and show the sum of all //the odd numbers squared in the range from 11 to 121. //Escriu el programa DOWHILE2.CPP, que fa servir un //cicle do-while per obtenir i mostrar la suma dels //quadrats dels enters senars en el ventall de l’11 //al 121. #include #define MIN 11 #define MAX 121 int sumOddSquared(int min, int max){ int res = 0 ,i; // for( i = min ; i <= max ; i += 2 ) // res += i*i; // i = min; // while ( i <= max ){ // res += i*i; // i += 2; // } i = min; do{ res += i*i; i += 2; }while ( i <= max ); return res; } void main(){ cout << "\n\nThe sum of all the odd numbers squared " << MIN << " to " << MAX <<" is " << sumOddSquared(MIN,MAX) << "\n\n\n"; }