自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(37)
  • 收藏
  • 关注

原创 C++ 统计n个学生三门课的平均成绩,统计各学生三门课的平均成绩。

统计n个学生三门课的平均成绩,统计各学生三门课的平均成绩。输入格式:输入学生的个数和这些学生的3门成绩(成绩为整数)输出格式:输出这些学生的平均成绩(整数),每个成绩占一行输入样例:298 97 9687 86 85输出样例:9786源程序代码:#include <iostream>using namespace std;//成绩类struct grade{ int a; int b; int c;};int main(){ int n;.

2022-04-19 23:54:00 4313

原创 C++ 1,3个变量从小到大排序 2,函数 3,变量的引用

#include <iostream>;using namespace std;void sort(int &a1, int &a2, int &a3){ //思想相当于冒泡排序 int temp; if (a1 > a2) { temp = a1; a1 = a2; a2 = temp; } if (a2 > a3) { temp = a2; a2 = a3; a3 = temp; } if (a1 &g...

2022-04-19 23:52:01 1280

原创 C++ 用同一个函数名对n个数据进行从小到大的排序,数据类型可以是整型、单精度、双精度型,用重载函数实现。

源程序代码:#include <iostream>using namespace std;int sort(int* p, int n){ for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (p[i] > p[j]) { int x; ..

2022-04-19 23:49:06 5266 5

原创 C++ 从键盘上输入10个数,按从小到大顺序输出。

2.从键盘上输入10个数,按从小到大顺序输出。源程序代码:#include <iostream>using namespace std;int main(){ int a[10]; int i, j, temp; for (i = 0; i < 10; i++) { cin >> a[i]; } //冒泡排序 从小到大排 for (i = 0; i < 10-1; ...

2022-04-19 23:45:37 6181 1

原创 C++输出

1.设计一个C++程序,输出以下信息:***************Hello!***************源程序代码:#include <iostream>using namespace std;int main(){ cout << "***************" << "\n" << " Hello!" << "\n" << "***************"; re...

2022-04-19 23:41:08 754

原创 3个变量从小到大排序 函数参数引用传递完成

//3个变量从小到大排序 函数参数引用传递完成#include <iostream>using namespace std;//函数参数引用传递完成void sort1(int& a1, int& b1, int& c1){ int temp; //3个if判断 思想和冒泡排序一样 if (a1 > b1) { temp = a1; a1 = b1; b1 = temp; } if (b1 > c1) .

2022-04-08 19:59:12 573

原创 设计一个类Date,成员函数实现日期的设置和输出

设计一个类Date,其私有数据成员有year(年)、month(月)、day(日),要求其满足下述要求。(1)要求有一个无参数的构造函数,其初始的年、月、日分别为:2000,1,1。(2)要求有一个带参数的构造函数,起参数分别对应年、月、日。(3)要求用一个成员函数实现日期的设置。(4)要求源程序代码:#include <iostream>using namespace std;class Date{private: int y..

2022-03-24 19:41:50 4176

原创 求5名学生的最高的分者的学号和姓名 指针做函数参数

#include <iostream>#include <string>using namespace std;class Student{public: string num; string name; float sc; Student() { num = "101"; name = "张三"; sc = 100.0; } Student(string n, str.

2022-03-24 18:11:17 451

原创 C++判断点和圆心的位置 类、构造函数、函数

#include <iostream>#include<cmath>using namespace std;//输入一个坐标和已知圆心的圆,判断点和圆心的位置//点类class point{public: double p_x; double p_y; };//圆类class circle{public: //内构函数 初始化圆心为(1,1) circle() { po.p_x = 1.0; po.p_y = 1.0; } //判断点.

2022-03-14 20:00:46 976

原创 修改完善后的c++猜数小游戏

//猜数游戏#include <iostream>#include<ctime>using namespace std;int main(){ //添加随机数种子 cout << "猜字游戏开始,你一共有6次猜字机会" << endl; srand((unsigned int)time(NULL)); //srand((unsigned int)time(0));和25行代码等价 //添加随机数 int num = rand() % 1.

2022-02-04 09:13:27 2185

原创 1474 查询记录(结构体专题)

代码如下:#include<stdio.h>#include<string.h>struct check{ char num[100]; char name[50]; int s1,s2,s3; char num2[100];};int main(){ int n; scanf("%d",&n); struct check s[n],t; int i; for(i=0;i<n;i++) {

2022-01-27 11:18:16 508

原创 1397 火车票退票费问题(函数专题)

代码如下:#include<stdio.h>#include<stdlib.h>double tpf(double prise){ double e; int t; t=prise*0.05*100; if((t%100)<25) { t=t/100*100; } else if((t%100)>=25&&(t%100)<=75) { t=t/

2022-01-27 11:16:09 372

原创 1322 I Love 闰年 闰年问题

#include<stdio.h>int main(){ int n; scanf("%d",&n); if((n%4==0&&n%100!=0)||n%400==0) { printf("Yes\n"); } else { printf("No\n"); } return 0;}

2022-01-27 11:13:16 400

原创 C++ 简单的通讯录管理系统

//通讯录管理系统#include<iostream>using namespace std;#include<string>#define MAX 1000//最大人数//联系人结构体struct person{ string m_name; string m_sex; int m_age; string m_phone;//电话 string m_addr;//住址};//通讯录结构体struct addressbooks{ struct pe.

2022-01-27 10:59:31 700

原创 (英雄-按年龄排序)结构体数组初始化 冒泡排序

#include <iostream>#include<ctime>#include<cmath>#include<string>using namespace std;struct hero{ string name; int age; string six;};void print(hero h[], int len){ for (int i = 0; i < len; i++) { cout << ".

2022-01-22 10:46:32 234

原创 结构体运用 打印三个老师姓名并各带五个学生name score

使用了随机数,结构体嵌套。//结构体运用 //打印三个老师并各带五个学生name score#include <iostream>#include<ctime>#include<cmath>#include<string>using namespace std;struct student{ string sname; int score;};struct teacher{ string tname; struct stu.

2022-01-22 10:04:20 361

原创 函数、数组和指针结合

//函数 数组 指针#include <iostream>#include<ctime>#include<cmath>using namespace std;void bubble_sort(int *a, int len){ for (int i = 0; i <len-1; i++) { for (int j = 0; j < len-1- i; j++) { if (a[j] > a[j + 1]) { .

2022-01-20 10:29:39 409

原创 简单的猜数游戏-C++

//猜数游戏#include <iostream>#include<ctime>using namespace std;int main(){ //添加随机数种子 cout << "猜字游戏开始,你一共有6次猜字机会" << endl; srand((unsigned int)time(NULL)); //srand((unsigned int)time(0));和25行代码等价 //添加随机数 int num = rand() % 1.

2022-01-16 23:29:59 2354

原创 do{}while(); 使用的注意事项

int a, b, c; int num=100; do { a = num % 10; b = num / 10 % 10; c = num / 100 % 10; if (a * a * a + b * b * b + c * c * c == num) { cout << num << endl; } num++; } while (num < 1000);do{}while()后面记得加“;”...

2022-01-16 23:19:03 4217

原创 7-40 情侣身高差

专家通过多组情侣研究数据发现,最佳的情侣身高差遵循着一个公式:(女方的身高)×1.09 =(男方的身高)。如果符合,你俩的身高差不管是牵手、拥抱、接吻,都是最和谐的差度。下面就请你写个程序,为任意一位用户计算他/她的情侣的最佳身高。输入格式:输入第一行给出正整数N(≤10),为前来查询的用户数。随后N行,每行按照“性别 身高”的格式给出前来查询的用户的性别和身高,其中“性别”为“F”表示女性、“M”表示男性;“身高”为区间 [1.0, 3.0] 之间的实数。输出格式:对每一个查询,在..

2022-01-14 15:55:43 101

原创 7-22 跟奥巴马一起画方块

#include <stdio.h>#include <stdlib.h>///四舍五入取整,n/2,///(1)n为奇数,9/2=4;要四舍五入4+1;///(2)n为偶数直接int main(){ int i,j,n; char c; scanf("%d %c",&n,&c); if(n%2==0) { for(i=0; i<n/2; i++) { .

2022-01-14 14:47:49 405

原创 7-45 宇宙无敌大招呼

#include <stdio.h>#include <stdlib.h>int main(){ char c[8]; scanf("%s",c); printf("Hello %s\n",c); return 0;}

2022-01-14 14:46:18 981

原创 【无标题】

scanf("%d%c",&n,&x);//错误写法 会运行错误#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){ int n,i,j; char x; scanf("%d%c",&n,&x);//错误写法 会运行错误 scanf("%d %c",&n,&x); if(n%2=...

2022-01-14 14:36:38 62

原创 判断素数的代码

(1)没优化代码#include <stdio.h>#include <stdlib.h>#include <math.h>int su(int x){ int i,ans=1;///0-不是素数,1-是素数 if(x==1) { ans=0; } for(i=2;i<x;i++) { if(x%i==0) { ans=0;

2022-01-14 13:34:29 492

原创 c语言中printf(“%02d”,m)的%02d是什么意思

%d是整型输出格式。02的意思是如果输出的整型数不足两位,左侧用0补齐。例如:int m=1;printf("%02d",m);1只有一位,左侧加0补齐,输出结果就是01如果输出的整型数不少于两位,则不用补。例如:int m=100;printf("%02d",m);输出结果是100int m=3;printf("%02d",m);输出结果是03。...

2022-01-12 21:19:54 12190

原创 C语言 函数 数组

就是说“数组作为函数的形参”实际上是一个指针类型的形参,即将来可以接受一个数组名表示的数组的起始地址!而并不是将一个数组的所有元素传给一个函数,仅仅传递的是一个小小的指针变量。比如,我们可定义下面的函数,第一个参数表示可以接受一个传入的数组doublegetAverage(intarr[],intsize){inti;doubleavg;doublesum=0;for(i=0;i<size;++i){sum+...

2022-01-12 14:55:34 1205

原创 二维数组行列互换

#include<stdio.h>int main(){ int m,n; scanf("%d%d",&m,&n); double a[m][n]; int i,j; for(i=0; i<m; i++) { for(j=0; j<n; j++) { scanf("%lf",&a[i][j]); } } ///行列互换 m...

2021-12-17 23:12:13 628

原创 四则运算1331

#include<stdio.h>#include<math.h>int main(){ double s1,s2; char op; scanf("%lf %c %lf",&s1,&op,&s2); switch(op) { case '+': printf("%.2f",s1+s2); break; case '-': printf("%.2f...

2021-12-17 23:06:38 176

原创 2021-11-12

输出左对齐占4位printf("%-4d",n);输出右对齐占20位printf("%20d",n);

2021-11-12 14:54:15 39

原创 2021-11-11

2021 11 11#include<stdio.h>int main(){int year,mouth,day;scanf("%d %d %d",&year,&mouth,&day);switch(mouth){case 1:day=day;break;case 2:day=31+day;break;case 3:day=59+day;break;case 4:day=90+day;break;case 5:day=120+da

2021-11-11 11:32:34 169

原创 2021-11-07

EOF–end of file 值=1;即文件结束标志。

2021-11-07 14:31:00 42

原创 2021-11-05

c语言中不能用表示次方,如23

2021-11-05 19:44:16 335

原创 2021-11-04

一个变量a,用-a不行,电脑不理解他的意思,在赋一下值,如b=-a。

2021-11-04 22:37:27 46

原创 2021-11-03

long int占位符是%ld。

2021-11-03 12:47:54 45

原创 2021-11-02

**这种类型的输出不能傻乎乎的复制输出,那是错的,需要用回车换行符\n来完成换行。

2021-11-02 12:24:28 47

原创 2021-11-01

c语言绝对值要用abs 还要加 #include<math.n>

2021-11-01 13:12:46 47

原创 2021-10-31

今天是刚学c语言的第二周,计科的大一新生,对计算机语言程序不了解,选择这个专业是因为该专业就业前景好,薪资高,为了钱。水平很差,scanf("%d %d",x,y);这样错误的语句都写出来了。正确的是scanf("%d %d",&x,&y); 取地址符号一定不能忘记在scanf中。...

2021-10-31 00:27:50 51 1

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除