4/10打卡
4/10打卡 c++ 课本例题
#include<bits/stdc++.h>
using namespace std;
class Frac{
public:
Frac(int a = 0, int b = 0 ){
for(int i = 2; i < a || i < b; i ++ ){
if(a % i == 0 && b % i == 0){
a /= i;
b /= i;
i = 2;
}
}
z = a;
m = b;
}
friend Frac operator + (Frac &c1, Frac &c2){
if(c1.m == c2.m) return Frac(c1.z + c2.z, c1.m);
else return Frac(c1.z * c2.m + c2.z * c1.m, c1.m * c2.m);
}
void display(){
cout << z << " " << m;
}
private:
int z, m;
};
#include<bits/stdc++.h> using namespace std;
#include<bits/stdc++.h> using namespace std;
#include<bits/stdc++.h>
using namespace std;
int mian(){
int day;
cin >> day;
switch (day){
case 0{
cout << "sunday" << endl;
break;
}
case 1{
cout << "monday" << endl;
break;
}
case 2{
cout << "tuesday" << endl;
break;
}
case 3{
#include<bits/stdc++.h>
using namespace std;
int main()
{
int year;
bool isleapyear;
cout << "Enter the year:";
cin >> year;
isleapyear = ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
if(isleapyear)
cout << year <<" is a leap year" << endl;
else
cout << year << "is not a leap year" << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int i = 1, sum = 0;
do {
sum += i;
i ++ ;
}while(i <= 10);
cout << sum <<endl;
return 0;
}
cout << "wensday" << endl; break; } case 4{ cout << "Thursday" << endl; break; } case 5{ cout << "Friday" << endl; break; } case 6{ cout << "Saturdday" << endl; break; } } return 0; }
const N = 4; int main(){ for(int i = 1; i <= N; i ++ ){ for(int j = 0; j < 30; j ++ ){ cout << " "; } for(int j = 0; j < 8 - 2 * i; j ++){ cout << " "; } for(int j = 0; j < 2 * i - 1; j ++ ){ cout << "*"; } cout << endl; } for(int i = 1; i <= N - 1; i ++ ){ for(int j = 0; j < 30; j ++){ cout << " "; } for(int j = 0; j < 7 - 2 * i; j ++ ){ cout << "*"; } cout << endl; } return 0; }
int main(){ int i = 1, sum = 0; while(i <= 10){ sum += i; i ++ ; } cout << sum <<endl; redturn 0; }
int main(){ int a, b, c, d; cin >> a >> b >> c >> d; Frac c1(a, b), c2(c, d), c3; c3 = c1 + c2; c3.display(); return 0; }
#include<bits/stdc++.h>
using namespace std;
int main(){
int x, y;
cout << "Enter x , y ";
cin >> x >> y;
if(x > y) cout << x << ">" << y << endl;
else if(x < y) cout << x << "<" << y << endl;
else cout << x << "=" << y << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int i = 1, sum = 0;
do {
sum += i;
i ++ ;
}while(i <= 10);
cout << sum <<endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
for(int i =1a ; i <= n; i++ ){
if(n % i == 0)
cout << i << " ";
cout << endl;
}
return 0;
}
浙公网安备 33010602011771号