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