结构体
#include<stdio.h>
#include<stdlib.h>
void addNum(int a,int b){
a++;
b++;
printf("子函数a和b的值是:%d,%d\n",a,b);
}
void main(){
int a = 20,b = 30;
printf("a和b的值是:%d,%d\n",a,b);
addNum(a,b);
printf("a自增后是:%d\tb自增后是:%d\n",a,b);
system("pause");
}
void add(int *a){
*a = 10;
}
void main(){
int a = 0;
add(&a);
printf("a的值是:%d\n",a);
system("pause");
}
void score(float f[5]){
for(int i= 0;i < 5;i++){
for(int j = 0;j < 4-i;j++){
if(f[j]>f[j+1]){
float temp;
temp = f[j+1];
f[j+1] = f[j];
f[j] = temp;
}
}
}
}
float grade[5];
printf("输入五个学生成绩:");
for(int i = 0;i < 5;i++){
scanf("%f",&grade[i]);
}
score(grade);
printf("排序后成绩:\n");
for(int i = 0;i < 5; i++){
printf("%5.2f\n",grade[i]);
}
int getMax(int *p){
int h = *p;
p++;
for(int i = 0;i < 5; i++){
if(h < *p){
h = *p;
}
p++;
}
return h;
}
int a[5],max;
printf("请输入五个数:");
for(int i = 0;i < 5; i++){
scanf("%d",&a[i]);
}
max = getMax(a);
printf("最大值是:%d\n",max);
char line[30];
int i,count = 0;
printf("请输入字符:\n");
gets(line);
i = 0;
while(line[i] != '\0'){
if(line[i] == ' ')
count++;
i++;
}
printf("\n其中的空格数为:%d\n",count++);
网友评论