//------------------------------------------------- // Jordi Binefa i Martínez // dubtes@excite.com // http://members.juara.com/asi //------------------------------------------------- //Write the program WHILE2.CPP, that uses a loop //("while" type) to get and show the sum of all //the odd numbers squared in the range from 11 to 121. //Escriu el programa WHILE2.CPP, que fa servir un cicle //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; } return res; } void main(){ cout << "\n\nThe sum of all the odd numbers squared from " << MIN << " to " << MAX <<" is " << sumOddSquared(MIN,MAX) << "\n\n\n"; }