- 博客(19)
- 收藏
- 关注
原创 假设某一班级有M名学生,没人考N门功课,试设计两个c++函数,(1)求第i个学生N门功课的平均分数。(2)求第j门课程的平均分数
#includeusing namespace std;float hhh(int a[]);float ppap(int b[]);const int M = 5, N = 5;void main(){cout int a[M][N], i, j, p,average1, average2;for (i = 0; i for (j = 0; j cin
2017-11-29 10:40:53 3578
原创 编写函数,在有n个整形元素的一维数组中查找关键码为key的数据,然后在主程序中调用该函数
#includeusing namespace std;void hhh(int a[], int key);const int n = 10;void main(){int a[n], key, i;for (i = 0; i {cin >> a[i];}cin >> key;hhh(a, key);}void hhh(int a[
2017-11-28 21:24:45 1920
转载 编写函数catStr(char str1[],char str2[])用于进行两个字符串的连接,编写函数lenStr()用于统计一个字符串的长度。编写函数cmpStr()用于判断两个字符串的大小。
#includeusing namespace std;int lenStr(char str[40]){int num = 0, i = 0;while (str[i] != '\0')num++, i++;return num;}int cmpStr(char str1[40], char str2[40]){int i = 0;while (s
2017-11-28 20:45:39 10466
原创 编写函数,将一个数据插入有序数组,要求插入后数组仍然有序
#includeusing namespace std;void sort(int array[], int n);void insert(int b[], int n, int data);const int N = 10;void main(){int i, array[N + 1], data;cout for (i = 0; i cin >> arr
2017-11-28 20:16:40 5432
原创 编写函数,输出大于a小于b的所有偶数,主函数读入两个正整数
#includeusing namespace std;void f(int a, int b);void main(){int a, b, tem;cin >> a >> b;if (a > b){tem = a;a = b;b = tem;}f(a, b);}void f(int a, int b){int i, j;
2017-11-26 23:27:23 1163
原创 编写函数,用递归法将一个n位整数转换为n个相应的字符
#includeusing namespace std;void intToChar(int n);void main(){int n;cout cin >> n;cout if (n {n = -n;cout }intToChar(n);}void intToChar(int n){int c;char ch;
2017-11-26 23:06:35 987
原创 编写函数,判断year是否为闰年,若是则返回1,否则返回0
#include using namespace std;int hhh(int year){int x;if (year % 100 != 0 && year % 4 == 0 || year % 100 == 0 && year % 400 != 0)x = 1;else x = 0;return x;}void main(){int a;c
2017-11-21 16:00:01 18494
原创 编写函数,将一维数组(array[10])的元素从小到大排序,在主函数中读入数组的元素
#includeusing namespace std;void hhh(int array[10]){int i, j, t;for (i = 0; i for(j=0;jif (array[j] >array[j + 1]){t = array[j];array[j] = array[j + 1];array[j + 1] = t;
2017-11-21 15:44:33 12369
原创 编写函数,已知三角形三边长,求三角形面积
#includeusing namespace std;double hhh(double a,double b ,double c ){double p;double s;p =( a + b + c)/2;s = sqrt(p*(p - a)*(p - b)*(p - c));return s; }void main(){do
2017-11-21 15:41:39 14191
原创 编写函数,其功能是求3个整数的最大值和最小值
includeusing namespace std;int max(int x,int y,int z){int t;if (x >y)t = x;else t = y;if (z > t)t = z;return t;}int min(int x,int y,int z){int t;if (x <y
2017-11-21 15:40:06 13419
原创 第四次实验 编写函数computNum( int num),它的功能是计算任意输入的一个正整数的各位数字之和,结果由函数返回
#includeusing namespace std;int num(int n){int i, a = 0;while (n / 10 != 0){i = n % 10;a = a + i;n = n / 10;}a = a + n;return a;}void main(){int x, y;cin >> x;y =
2017-11-17 16:55:24 6997
原创 输入两个字符串a,b.要求不用strcat函数把串b的前五个字符连到串a,如果b的长度小于5,则全部元素连入a
#include using namespace std;void main(){char a[80], b[20];int i, j;cout cin >> a[80];cout cin >> b[20];i = 0;while (a[i] != '\0')i++;j = 0;while (b[j] != '\0 '
2017-11-16 16:40:36 6989
原创 输入5个职工的职工号,基本工资,浮动工资和奖金,统计并输出最高的职工的职工号和总工资
#includeusing namespace std;void main(){int person[5][5], i, j, max;for(i=0;ifor (j = 0; j {cin >> person[i][j];}for (i = 0; i person[i][4] = 0;for (j = 1; j {person[0][4]
2017-11-13 21:07:19 2125
原创 第二次实验第五题。使用二维数组输出表格
#includeusing namespace std;void main(){int i, j;float a[4][6];a[3][5] = 0;cout for (i = 0; i for (j = 0; j cin >> a[i][j];for (i = 0; i {a[i][5] = 0;for (j = 0; j {a[i
2017-11-13 08:49:14 1016
原创 102页第八题。每个苹果0.8元,第一天买两个,从第二天开始每天买的数量是前一天的2倍,直到当天购买苹果数量超过100,问每天平均花多少钱。
#includeusing namespace std;void main(){double x, ave;int n = 2, i, sum = 2;for (i = 1; n {n = 2 * n;sum = sum + n;}x = 0.8*sum;ave = x / i;cout getchar();getchar();}
2017-11-09 23:16:29 13820
原创 统计N 个学生的成绩并输出低于平均水平的人数
#includeusing namespace std;void main(){float s, sum=0;int a[10], i, n = 0;for (i = 0; i {cin >> a[i];sum += a[i];}s = sum / 10;for (i = 0; i {if (a[i] n++;}cout
2017-11-08 21:27:28 6039
原创 用冒泡法给四个数据排序
#includeusing namespace std;void main(){int a[4], i, j, t;for (i = 1; i cin >> a[i];for (i = 1; i for (j = 1; j if (a[j] > a[j + 1]){t = a[j];a[j] = a[j + 1];a[j + 1] = t;
2017-11-08 13:53:27 1059
转载 打印100-999之间所有的水仙花数,水仙花数是一个三位数,各位数的立方和等于该数本身
#includeusing namespace std;void main(){int n, a, b, c;cout for (n = 100; n {c = n % 10;b = n / 10 % 10;a = n / 100;if (n == a*a*a + b*b*b + c*c*c)cout }}
2017-11-07 17:14:48 2600
转载 c++102页第三题。用if-else,switch实现分层业绩奖励
#includeusing namespace std;void main(){int x, c;double y;cin >> x;if (x / 1000 == 0)c = 1;else if (x /1000 >= 1 && x / 1000 c = 2;else if (x /1000 >= 5 && x / 1000 c = 3;e
2017-11-07 16:30:11 239
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人