一,
1.
#include <iostream>
using namespace std;
int main() {
int s=0;
for (int i = 1; i <= 10; i++) {
int temp = i;
for (int j = 1; j < temp; j++) {
temp *= j;
}
s += temp;
}
cout << s << endl;
return 0;
}
2.
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int sum = 0;
for (int i = 1; i < n; i++) {
if (n % i == 0)
sum += i;
}
cout << sum << endl;
}
3.
#include <iostream>
using namespace std;
void Fun(int m, int n);
int main() {
int a, b;
cin >> a >> b;
Fun(a, b);
}
void Fun(int m, int n) {
int div;
int mul;
int max = m;
int min = n;
if (m < n) {
max = n;
min = m;
}
for (int i = min; i >= 1; i--) {
if (m % i == 0 && n % i == 0) {
div = i;
break;
}
}
for (int i = max; i; i++) {
if (i % m == 0 && i % n == 0) {
mul = i;
break;
}
}
cout << m << "与" << n << "的最大公约数为:" << div << " 最小公倍数为:" << mul << endl;
}
4.
#include <iostream>
#include <fstream>
#include <ctype.h>
using namespace std;
int main() {
ofstream outFire;
outFire.open("Number.txt");
string str;
cin >> str;
int len = str.length();
for (int i = 0; i < len; i++) {
if (isdigit(str[i]) != 0)
outFire << str[i];
}
outFire.close();
}
5.
#include<iostream>
#include<cstdlib>
#include <malloc.h>
using namespace std;
typedef struct Student{
string Num;
string Name;
double Grade;
}Student;
typedef struct lNode {
Student* inform;
lNode* next;
}lNode;
lNode* CreateList(int n) {
lNode* head, * normal, * end;/*创建头节点,其他节点,和尾节点*/
head = new lNode;
head->inform = new Student;
end = head;
for (int i = 0; i < n; i++) {
normal = new lNode;
normal->inform = new Student;
cout << "input the number :";
cin >> normal->inform->Num;
cout << "input the name :";
cin >> normal->inform->Name;
cout << "input the grade :";
cin >> normal->inform->Grade;
cout << "----------------------------------" << endl;
end->next = normal;
end = normal;
}
end->next = NULL;/*链表的最后指向一个新地址*/
return head;
}
void output_point(lNode* point)
{
cout << "the number is :" << point->inform->Num << endl;
cout << "the name is :" << point->inform->Name << endl;
cout << "the grade is :" << point->inform->Grade << endl;
cout << "----------------------------------" << endl;
}
void output_list(lNode* point)
{
lNode* p;
p = point;
cout << endl << endl << endl;
while ((p = p->next) != NULL)
{
output_point(p);
}
}
int main() {
lNode* head;
head = CreateList(3);
output_list(head);
}
二,
1.
#include <iostream>
#include <fstream>
#include <ctype.h>
using namespace std;
int main() {
ofstream outFire;
outFire.open("a1.txt");
int arr[10];
int sum = 0;
for (int i = 0; i < 10; i++) {
cin >> arr[i];
sum += arr[i];
}
sum /= 10;
outFire << sum << endl;
for (int i = 0; i < 10; i++) {
if (arr[i] < sum)
outFire << " " << arr[i] ;
}
outFire.close();
}
2.
#include <iostream>
#include <vector>
using namespace std;
void Sort(int n, vector<int> arr);
int main() {
int n;
cin >> n;
vector<int> arr;
arr.resize(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
Sort(n, arr);
return 0;
}
void Sort(int n, vector<int> arr) {
for (int i = n; i > 0; i--) {
for (int j = 1; j < i; j++) {
if (arr[j - 1] > arr[j]) {
int temp = arr[j - 1];
arr[j - 1] = arr[j];
arr[j] = temp;
}
}
}
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
}
3.
#include <iostream>
#include <fstream>
#include <ctype.h>
using namespace std;
int main() {
string str;
cin >> str;
int len = str.length();
int temp = 0;
for (int i = 0; i < len; i++) {
if (isdigit(str[i]) != 0) {
temp *= 10;
int a = str[i] - '0';
temp += a;
}
if (isalpha(str[i]) != 0) {
if (temp != 0 && temp % 7 == 0)
cout << temp << endl;
temp = 0;
}
}
return 0;
}
4.
#include <iostream>
using namespace std;
bool hws(int n, int m);
int main() {
int n;
cin >> n;
int flag = 0;
for (int i = 10000; i < 999999; i++) {
if (hws(i, n)) {
cout << i << endl;
flag = 1;
}
}
if (flag == 0)
cout << -1 << endl;
return 0;
}
bool hws(int n,int a)
{
int ans = 0, m = n;
int temp = 0;
int sum = 0;
while (m > 0)
{
temp = m % 10;
sum += temp;
ans = ans * 10 + temp;
m /= 10;
}
if (ans == n && sum == a)
return true;
else
return false;
}
三,
1.
#include <iostream>
using namespace std;
int main() {
double result = 0.0;
for (int i = 0; i < 50; i++) {
int m = 1;
if (i % 2 != 0) {
m = -1;
}
double a = (1.0 / (2 * i + 1))*m;
result += a;
}
cout << result << endl;
}
2.
#include <iostream>
#include <cmath>
using namespace std;
double Fun(int arr[]);
int main() {
int arr[5] = {1,2,3,4,5};
double sum = Fun(arr);
cout << sum << endl;
}
double Fun(int arr[]) {
double result=0;
for (int i = 0; i < sizeof(arr); i++) {
double temp = sqrt(arr[i]);
result += temp;
}
return result;
}
3.
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
getline(cin, str);
for (int i = 0; i < str.length(); i++) {
if (str[i] != ' ') {
cout << str[i];
}
}
return 0;
}
4.
#include <iostream>
using namespace std;
struct Student
{
int Num;
string Name;
char Sexy;
double Chinese;
double Math;
double English;
};
int main() {
Student arr[50];
for (int i = 0; i < 50; i++) {
cout << "请输入第" << i+1 << "位同学的信息(学号,姓名,性别,语文成绩,数学成绩,英语成绩):" << endl;
cin >> arr[i].Num >> arr[i].Name >> arr[i].Sexy >> arr[i].Chinese >> arr[i].Math >> arr[i].English;
}
double a = 0.0;
double b = 0.0;
double c = 0.0;
for (int i = 0; i < 50; i++) {
a += arr[i].Chinese;
b += arr[i].Math;
c += arr[i].English;
}
a /= 50.0;
b /= 50.0;
c /= 50.0;
cout << a << " " << b << " " << c;
return 0;
}
5.
#include <iostream>
#include <fstream>
#include <cctype>
#include <algorithm>
using namespace std;
int main() {
ofstream outFile;
outFile.open("str.txt");
string str;
cin >> str;
transform(str.begin(), str.end(), str.begin(), ::tolower);
outFile << str;
outFile.close();
}
部分参考来源: