#include <iostream>
using namespace std;
int main()
{
int a,b,s;
cout << "podaj a: ";
cin >> a;
cout << "podaj b: ";
cin >> b;
s=0;
if (a%2==0) {
cout << "suma liczb: ";
for (int i=a; i<=b; i++ ) {
if (i%2==0) {
cout << i << ", ";
s=s+i;
}
cout << " to: " << s;
if (a%2!=0) {
if (i%2!=0) {
return 0;
Odpowiedź:
dodatkowo w pliku
Wyjaśnienie:
int a,b,i,suma;
cout<<"podaj a: ";
cin>>a;
cout<<"podaj b: ";
cin>>b;
suma = 0;
for (i=a; i<=b; i=i+2)
suma=suma+i;
cout<<"suma = "<<suma<<endl;
" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.
#include <iostream>
using namespace std;
int main()
{
int a,b,s;
cout << "podaj a: ";
cin >> a;
cout << "podaj b: ";
cin >> b;
s=0;
if (a%2==0) {
cout << "suma liczb: ";
for (int i=a; i<=b; i++ ) {
if (i%2==0) {
cout << i << ", ";
s=s+i;
}
}
cout << " to: " << s;
}
if (a%2!=0) {
cout << "suma liczb: ";
for (int i=a; i<=b; i++ ) {
if (i%2!=0) {
cout << i << ", ";
s=s+i;
}
}
cout << " to: " << s;
}
return 0;
}
Odpowiedź:
dodatkowo w pliku
Wyjaśnienie:
#include <iostream>
using namespace std;
int main()
{
int a,b,i,suma;
cout<<"podaj a: ";
cin>>a;
cout<<"podaj b: ";
cin>>b;
suma = 0;
for (i=a; i<=b; i=i+2)
{
suma=suma+i;
}
cout<<"suma = "<<suma<<endl;
return 0;
}