基礎プログラミング復習用課題 解答例

基礎プログラミング復習用課題
—― 第 3 回
4 月 29 日
<問題 1>
#include<iostream>
using namespace std;
int main(){
int x = 10;
double y = 0.04;
cout << "x=" << x << ", y=" << y << endl;
return 0;
}
<問題 2>
#include<iostream>
using namespace std;
int main(){
bool x = true, y = false;
cout << "x=" << x << ", y=" << y << endl;
return 0;
}
̶
解答例
<問題 3>
#include<iostream>
using namespace std;
int main(){
int x = 'a';
cout << "x=" << x << endl;
return 0;
}
<問題 4>
#include<iostream>
using namespace std;
int main(){
int x = 10;
double y = 0.04;
cout << "x=" << x << ", y=" << y << endl;
x =-4;
y=1.25;
cout << "x=" << x << ", y=" << y << endl;
return 0;
}
<問題 5>
#include<iostream>
using namespace std;
int main(){
int x = 4, y = -2;
cout << "x=" << x << ", y=" << y << endl;
x = y;
cout << "x=" << x << ", y=" << y << endl;
return 0;
}
<問題 6>
#include<iostream>
using namespace std;
int main(){
int x = 2.5;
double y = 2.5;
cout << "x=" << x << ", y=" << y << endl;
return 0;
}
<問題 7>
#include<iostream>
using namespace std;
int main(){
int x, y,z;
cout << "Input three integers : ";
cin >> x >> y >> z;
cout << "Num1=" << x << ", Num2=" << y << ", Num3=" << z <<
endl;
cout << "Num3=" << z << ", Num2=" << y << ", Num1=" << x <<
endl;
return 0;
<問題 8>
#include<iostream>
using namespace std;
int main(){
const int pi=3.14;
pi = 1.5;
return 0;
}
<問題 9>
#include<iostream>
using namespace std;
int main(){
int x=9, y =4;
cout << x << "+" << y << "=" << x+y;
cout << ", "<< x << "-" << y << "=" << x-y;
cout << ", "<< x << "*" << y << "=" << x*y;
cout << ", "<< x << "/" << y << "=" << x/y;
cout << ", "<< x << "%" << y << "=" << x%y << endl;
return 0;
}
<問題 10>
#include<iostream>
using namespace std;
int main(){
int x, y;
cout << "Input two integers : ";
cin >> x >> y;
cout << x << "+" << y << "=" << x+y;
cout << ", "<< x << "-" << y << "=" << x-y;
cout << ", "<< x << "*" << y << "=" << x*y;
cout << ", "<< x << "/" << y << "=" << x/y;
cout << ", "<< x << "%" << y << "=" << x%y << endl;
return 0;
}
<問題 11>
#include<iostream>
using namespace std;
int main(){
double x, y;
cout << "Input two real numbers : ";
cin >> x >> y;
cout << x << "+" << y << "=" << x+y;
cout << ", "<< x << "-" << y << "=" << x-y;
cout << ", "<< x << "*" << y << "=" << x*y;
cout << ", "<< x << "/" << y << "=" << x/y << endl;
return 0;
}