标签:输出 key == 维数 average arch 空格 回文 out
下面是题目
后面有代码
1.键盘输入3个整数a,b,c值,求一元二次方程a*X∧2+b*X+c=0(a≠0)的根,结果保留两位小树。
2.编写一个口令输入程序,让用户不停输入口令,直到输对为止,假设口令为100。
3.若一个数恰好等于除它本身外的所有因子之和,则这个数成为完数,例:6点因数是1,2,3。且6=1+2+3所以6是完数,求100以内的所有完数,并输出。
4.编程从键盘输入10个数,求它们的方差。
5.编程将递增数列10,20,30,40,50,60,70,80,90,100保存到数组中,再从键盘输入一个整数,将它插入该数列中,使之扔为一个递增数列。
6.键盘输入一个M*N的二位数组,求该数组各行的平均值,将结果放到一个数组中,并输出。
7.编写函数判断一个整数是否为回文数。主函数中调用该函数,输出1000到9000之间的所有回文数,,每行输出十个数字。回文是指正读和倒读都一样的数字。如98789。
8.编写函数power()用来求n∧k的值。在主函数中输入两个正整数n和k,调用函数power,求1∧k+2∧k+…+n∧k的值并输出结果。
9.编程求C(n,m)=m!/n!*(m-n)!,要求在主函数中输入自然数m,n的值并输入结果。若输入错误(即输入的不是自然数),提示错误信息。
10.编写函数输入月份,输出该月的英文名,要求用指针数组实现。
(附加题)11. 加密程序:由键盘输入明文,通过加密程序转换成密文并输出到屏幕上。 算法:明文中的字母转换成其后的第4个字母,例如,A变成E(a变成e),Z变成D,非字母字符不变;同时将密文每两个字符之间插入一个空格。例如,China转换成密文为G l m r e。要求:在函数change中完成字母转换,在函数insert中完成增加空格,用指针传递参数。
附加题别问了 我也忘了怎么写的了
欢迎小姐姐加QQ
2473183730
#include <iostream> #include<stdlib.h> #include<stdio.h> #include<math.h> using namespace std; /******************************C语言测试*******************************************************/ void test001() { int a, b, c; double decide, x1, x2, m, n; cout << "Please key in a,b,c"; cin >> a >> b >> c; decide = (double)b * (double)b - 4 * (double)a * (double) c; if (decide < 0) { printf("The number is roung \n"); } else { m = -b / (2 * a); n = sqrt(decide) / (2 *(double) a); x1 = m + n; x2 = m - n; system("color 02"); printf("The answer is:\nx1=%.2f\nx2=%.2f\n", x1, x2); } } void test002() { int b; cout << "Please key in the answer\n"; while (1) { cin >> b; if (b == 100) { break; } else { system("color 02"); cout << " 输入错误,再来一次\n"; } } system("color 02"); cout << "我的妈呀 你终于输入正确了"; } void test003() { int i, j, sum = 0; for (i = 2; i <= 100; i++) { for (j = 1; j < i; j++) { if (i % j == 0) { sum = sum + j; } } if (sum == i) { printf("%d \n", i); } sum = 0; } } void test004() { int a[11], i, m,sum,average,ans,answer; sum = 0; ans = 0; for (i = 0; i < 10; i++) { cin >> a[i]; } for (i = 0; i < 10; i++) { sum= sum+ a[i]; } average = sum / 10; cout << sum <<endl<< average<<endl; for (i = 0; i < 10; i++) { ans = ans + pow((a[i] - average), 2); } answer = ans / 10; cout << answer; } void test005() { int m, n, v,i,c; int a[15] = { 10,20,30,40,50,60,70,80,90,100 }; int j[15] = { 10,20,30,40,50,60,70,80,90,100 }; cin >> v; for (i = 0; i < 10; i++) { if (v > a[i] && v < a[i+1]) { m = i + 1; break; } } n = m; for (n; n<14; n++) { a[n+1] = j[n]; } a[m] = v; for (c = 0; c <=12; c++) { cout << a[c]<<endl; } } void test006() { } void test007() { int a, i = 0; for(a=1000;a<9001;a++) { if(a/1000%10==a/1%10 && a/100%10==a/10%10) { printf("%5d", a); i++; if(i==9) { printf("\n"); i = 0; } } } } void test008(int n,int k) { int m,sum=0; for (m = 1; m <= n; m++) { sum = sum + pow(m, k); } cout << sum; } int jiecheng( int m) { int Plus=1; for (int i = 1; i <= m;i++) { Plus= Plus*i; } return Plus; } void test009() { double answer; int n, m; cout << "Please key in two number" << endl; cin >> n >> m; if (n == int(n) && m == int(m) && m > 0 && n > 0) { answer =(double) jiecheng(m) / (double)(jiecheng(n) * (double)jiecheng(m - n)); cout << answer; } else { cout << "error"; } } void test010() { int i; const char* p[12] = { "January","February","March","April","May","June","July","August","September","October","November","December" }; printf("please input your number of month:"); cin >> i; printf("\n"); // i = i - 1; // printf("The month is:%s\n", *p+i); printf("The month is:%s\n", p[i-1]); } void test010_SECOND() { int i; char p[12][30] = { "January","February","March","April","May","June","July","August","September","October","November","December" }; printf("please input your number of month:"); cin >> i; char* a; a = p[12]; printf("\n"); printf("The month is:%s\n", *(p+i - 1)); } void test006() { int a, b, c = 0, d; int column, row; int sum[100] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; cout << "输入二维动态数组的行数和列数" << endl; cin >> row >> column; int n1, i; int** array; array = (int**)malloc(sizeof(int*) * row); for (int i = 0; i != row; i++) array[i] = (int*)malloc(sizeof(int) * column); int* average; n1 = row; average = (int*)malloc(n1 * sizeof(int));//动态一维数组 cout << "输入二维数组"<<endl; for (int j = 0; j != row; j++) { for (int k = 0; k != column; k++) { cin >> array[j][k]; } } for (int j = 0; j != row; j++) { for (int k = 0; k != column; k++) { cout << array[j][k]; } } /* for (a = 0; a <= row; a++) { for (b = 0; b < column; b++) { sum[a] = sum[a] + array[a][b]; } average[a] = sum[a] / row; } for (c = 0; c <= row; c++) { cout << average[c]; } */ //释放空间 for (int i = 0; i != row; i++) { free(array[i]); } free(array); free(average); } int main() { test001(); test002(); test003(); test004(); test005(); test006(); test007(); int a, b; cin >> a >> b; test008(a,b); test009(); test010(); return 0; }
标签:输出 key == 维数 average arch 空格 回文 out
原文地址:https://www.cnblogs.com/Loving-Q/p/11963770.html