⑴ c語言的問題
按題意分別用到if和switch。
數組我懶得輸入71個成績,直接給初值,你想輸入,把常量N改成71,然後用循環scanf給score數組賦值好了。
#include<stdio.h>
#defineN10//學生人數
voidprintfA(int*a);
voidinit(int*scores,int*a);
intmain()
{
intscores[N]={90,91,92,81,82,71,75,65,68,50},a[5]={0};//a數組分別對應分數段,90~100,80~89,70~79,60~69,小於60
init(scores,a);
printfA(a);
return0;
}
voidinit(int*scores,int*a)
{
inti;
for(i=0;i<N;i++)
if(scores[i]>=90&&scores[i]<=100)
a[0]++;
elseif(scores[i]>=80&&scores[i]<=89)
a[1]++;
elseif(scores[i]>=70&&scores[i]<=79)
a[2]++;
elseif(scores[i]>=60&&scores[i]<=69)
a[3]++;
elseif(scores[i]<60)
a[4]++;
}
voidprintfA(int*a)
{
inti;
for(i=0;i<5;i++)
switch(i)
{
case0:printf("分數段90~100的人數:%d
",a[i]);break;
case1:printf("分數段80~89的人數:%d
",a[i]);break;
case2:printf("分數段70~79的人數:%d
",a[i]);break;
case3:printf("分數段60~69的人數:%d
",a[i]);break;
case4:printf("分數段小於60的人數:%d
",a[i]);break;
}
}
⑵ C語言:有一個數組,內放5個學生成績,求平均分,用函數實現。
代碼如下:
#include<stdio.h>
voidshow_score(intscores[],intn){
printf("scores:");
for(inti=0;i<n;i++)
printf("%d",scores[i]);
printf(" ");
}
floatget_avg(intscores[],intn){
intsum=0;
for(inti=0;i<n;i++)
sum+=scores[i];
returnsum*1.0/n;
}
intmain(){
intscores[5]={60,70,80,90,80};
show_score(scores,5);
printf("average:%.2f",get_avg(scores,5));
getchar();
return0;
}
運行結果如下:
望採納~
⑶ C語言指針問題 *score 與score 有什麼區別
score是二維數組指針常量.看到指針,你第一反應是想它指向什麼.對於score,它指向的是一維數組score[0], 而score[0]它也是個一維數組指針常量(同樣,你也得馬上反應過來score[0]是指向score[0][0]的).所以*score就是score[0]了,所以average(*score, 12)就是把score[0][0]的地址和score的元素總個數傳給了該函數咯.
再看下search的函數定義:search(float (*p)[4], int n).
float (*p)[4]; //看聲明先看變數名,然後由右往左看.如果遇到括弧則先看括弧里的.所以這聲明是說:p是個指針(p的右邊是括弧,所以先看括弧里的.'*'即代表是個指針),這指針指向一個數組(括弧看完後就往右看),該數組有4個float型元素.
即p為數組指針(後面兩個字說明它是指針,前面兩個字說明它指向一個數組.就像我們說美女一樣,後面一個字說明它是女人,前面一個字才說明它是美麗的.如果是指針數組則說明它先是個數組,然後它的元素為指針,那麼該定義為:float *p[4])
簡單點說float (*p)[4]即聲明p指向有4個float型元素的數組,而上面我說了,score也是指向一維數組score[0]的,而score[0]正是有4個float型元素的數組.即p和score是同類型的指針(只不過p是指針變數,score是指針常量).
所以search(score,2)中的實參score是可以作為"void search(float (* p)[4],int n)"這函數的形參p的(因為類型一樣).它是把數組名和2傳給了該函數.(順便提下,score[n][i]=*(*(score+n)+i),而score和p是同類型的,所以*(*(p+n)+i)即是score[n][i])
⑷ C語言,編寫一程序:3個學生,4門功課,求各行各列的平均成績。
//用二維數組,行和列的最後一個存儲單元用來存它那行或列的平均成績
#include<stdio.h>
int
main()
{
int
i,j;
float
scores[4][5]={{0},{0},{0},{0}};
for(i=0;i<3;i++)
{
printf("請輸入第%d個學生的4門功課成績\n",i+1);
for(j=0;j<4;j++)
scanf("%f",&scores[i][j]);
printf("\n");
}
for(i=0;i<3;i++)
//求各行的平均成績
{
for(j=0;j<4;j++)
scores[i][4]+=scores[i][j];
scores[i][4]/=4;
}
for(j=0;j<4;j++)
//求各列的平均成績
{
for(i=0;i<3;i++)
scores[3][j]+=scores[i][j];
scores[3][j]/=3;
}
printf("各行的平均成績為\n");
for(i=0;i<3;i++)
printf("%f
",socres[i][4]);
printf("各列的平均成績為\n");
for(j=0;j<4;j++)
printf("%f
",scores[3][j]);
return
0;
}
⑸ C語言編程程序,成績排序並求最高低分
最簡單的冒泡法:
float StudentMark[20];//20學生成績
//賦值過程省略
float Temp;//中間變數
for(int i=0;i<20-1;i++) //冒泡法
for(int j=1;j<20-i;j++)
{
if(StudentMark[j]<StudentMark[j-1})
Temp=StudentMark[j-1]; //交換數據
StudentMark[j-1]=StudentMark[j];
StudentMark[j]=Temp;
}
⑹ c 語言中 score是什麼意思
在C語言中沒有score這個保留字,換句話它在C語言中只能算是一個標識符,沒有特殊的語法功能。
一般來說C語言的標識符,有兩個基本的使用原則。
1、要符合語法要求,C語言中規定,標識符有數字、字母、下劃線(_)組成,而且第1符號只能為字母或者下劃線。
2、標識符的命名,盡量便於閱讀。如問題中的score用於表示分數,就容易理解。
⑺ C語言 score的意思
在C語言中沒有score這個保留字,換句話它在C語言中只能算是一個標識符,沒有特殊的語法功能。
一般來說C語言的標識符,有兩個基本的使用原則。
1、要符合語法要求,C語言中規定,標識符專有數字、字母、下劃線(屬_)組成,而且第1符號只能為字母或者下劃線。
2、標識符的命名,盡量便於閱讀。如問題中的score用於表示分數,就容易理解。
⑻ c語言排序問題
C語言程序:
#include <stdio.h>
#define N 15
void show(int totalScores[], int scores1[], int scores2[], int scores3[]);
void sort(int totalScores[], int scores1[], int scores2[], int scores3[]);
void main()
{
int totalScores[] = {255, 250, 275, 225, 225, 245, 250, 190, 220, 220, 275, 245, 230,
245, 250 };
int scores1[] = {80, 85, 90, 75, 75, 82, 85, 65, 70, 65, 95, 85, 75, 80, 85};
int scores2[] = {85, 82, 90, 85, 80, 83, 85, 60, 75, 75, 90, 80, 70, 85, 80};
int scores3[] = {90, 83, 95, 65, 70, 80, 80, 65, 75, 80, 90, 80, 85, 80, 85};
//輸出排序前的成績列表
printf("排序前:
");
show(totalScores, scores1, scores2, scores3);
//對成績排序
sort(totalScores, scores1, scores2, scores3);
printf("
排序後:
");
show(totalScores, scores1, scores2, scores3);
}
void show(int totalScores[], int scores1[], int scores2[], int scores3[])
{
printf("序號 總分 得分1 得分2 得分3
");
printf("---------------------------------------
");
for(int i=0; i<N; i++)
{
printf("%2d ", i+1);
printf("%3d %3d %3d %3d
", totalScores[i], scores1[i], scores2[i], scores3[i]);
}
}
void sort(int totalScores[], int scores1[], int scores2[], int scores3[])
{
int i, j;
int temp;
for(i=0; i<N-1; i++)
{
for(j=0; j<N-1-i; j++)
{
if((totalScores[j] < totalScores[j+1])
|| ((totalScores[j] == totalScores[j+1]) && (scores1[j] < scores1[j+1]))
|| ((totalScores[j] == totalScores[j+1]) && (scores1[j] == scores1[j+1]) && (scores2[j]
< scores2[j+1]))
|| ((totalScores[j] == totalScores[j+1]) && (scores1[j] == scores1[j+1]) && (scores2[j]
== scores2[j+1]) && (scores3[j] < scores3[j+1])))
{
temp = totalScores[j];
totalScores[j] = totalScores[j+1];
totalScores[j+1] = temp;
temp = scores1[j];
scores1[j] = scores1[j+1];
scores1[j+1] = temp;
temp = scores2[j];
scores2[j] = scores2[j+1];
scores2[j+1] = temp;
temp = scores3[j];
scores3[j] = scores3[j+1];
scores3[j+1] = temp;
}
}
}
}
運行結果:
⑼ C語言編程:學生成績排序
#include <stdio.h>
#include <stdlib.h>
int main() {
struct student {
int num;
float scores;
};
student *stu = new student;
float insert = 0, temp = 0;
int i = 0;
for (; insert != -1; i++) {
printf("請輸入學生成績(結束輸入-1):");
scanf("%f", &insert);
stu[i].num = i + 1;
stu[i].scores = insert;
}
for (int m = 0; m < i - 2; m++) {
for (int n = 0; n < i - 2; n++) {
temp = stu[n].scores;
if (temp < stu[n + 1].scores) {
stu[n].scores = stu[n + 1].scores;
stu[n + 1].scores = temp;
temp = stu[n].num;
stu[n].num = stu[n+1].num;
stu[n+1].num = (int)temp;
}
}
}
for (int j = 0 ; j < i - 1 ; j++){
printf("%s%d%s\t%s%d\t%s%.2f\n","第",j+1,"名:","號數:",stu[j].num,"成績:",stu[j].scores);
}
system("PAUSE");
return 0;
}
⑽ C語言編程,兩個班,輸入每個班成績,求每個班平均成績,並求每個班低於80分的人數(人數分數自己設)
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#defineCOUNT50//每班人數上限設定
//定義一個班級人數及成績的結構體類型
typedefstructcl
{
intnumbers;//班級人數
intscores[COUNT];//每人分數
}CLASS;
//設置班級的人數
voidset_number(CLASS*cls,intnumber);
//設置班級人員的成績
voidset_scores(CLASS*cls,int*scores);
//獲取班級的平均成績
floatget_average(constCLASS*cls);
//隨機生成班級的成績信息
voidget_score(int*scores,intn);
//列印成績信息
voidprint_scores(constint*scores,intn);
//獲取班級低於80分的人數
intget_numbers_under80(constCLASS*cls);
intmain()
{
CLASScls1,cls2;//創建兩個班級對象
intscores[COUNT]={0};//定義存儲成績的數組
intnums1=0,nums2=0;//定義班級人數變數
//接收並校驗班級的人數信息
printf("請輸入班級1的人數(50以內):");
scanf("%d",&nums1);
while(nums1>COUNT)
{
printf("人數輸入錯誤,請重新輸入:");
scanf("%d",&nums1);
}
printf("請輸入班級2的人數(50以內):");
scanf("%d",&nums2);
while(nums2>COUNT)
{
printf("人數輸入錯誤,請重新輸入:");
scanf("%d",&nums2);
}
//設置班級1的相關信息
get_score(scores,nums1);
printf("班級1的成績信息: ");
print_scores(scores,nums1);
set_number(&cls1,nums1);
set_scores(&cls1,scores);
//設置班級2的相關信息
get_score(scores,nums2);
printf("班級2的成績信息: ");
print_scores(scores,nums2);
set_number(&cls2,nums2);
set_scores(&cls2,scores);
printf("班級1的平均成績[%.2f] ",get_average(&cls1));
printf("班級2的平均成績[%.2f] ",get_average(&cls2));
printf("班級1中低於80分的人數[%d] ",get_numbers_under80(&cls1));
printf("班級2中低於80分的人數[%d] ",get_numbers_under80(&cls2));
return0;
}
voidset_number(CLASS*cls,intnumber)
{
cls->numbers=number;
}
voidset_scores(CLASS*cls,int*scores)
{
inti=0;
for(;i<cls->numbers;i++)
{
cls->scores[i]=scores[i];
}
}
floatget_average(constCLASS*cls)
{
inti=0;
floatsum=0.0;
for(;i<cls->numbers;i++)
{
sum+=cls->scores[i];
}
returnsum/cls->numbers;
}
//為了方便,使用隨機數據代表成績
voidget_score(int*scores,intn)
{
inti=0;
srand(time(NULL));
for(;i<n;i++)
{
scores[i]=rand()%100+1;
}
}
voidprint_scores(constint*scores,intn)
{
inti=0;
for(;i<n;i++)
{
if(0!=i&&0==i%10)
printf(" ");
printf("%d",scores[i]);
}
printf(" ");
}
intget_numbers_under80(constCLASS*cls)
{
inti=0,nums=0;
for(;i<cls->numbers;i++)
{
if(80>cls->scores[i])
nums++;
}
returnnums;
}