今天也是刷题的一天
题1
解答:
#include<iostream>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
if (i % 10 % 2 == 1 && i%10 !=9)
cout << i << endl;
}
return 0;
}
题2
解题:
#include<iostream>
using namespace std;
int main() {
int n, i=1, s=1;
cin >> n;
while (i <= n) {
s *= i;
i++;
}
cout << s << endl;
}
题3
解答:
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
int n ;
float s = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
s += float(1.0 / i);
}
printf("%.3f\n", s);
return 0;
}