輸入若干個學生的若干個成績
1. 2、輸入若干個學生的成績(以-1為結束標志),要求統計不及格的學生人數。
恣
2. 從鍵盤上輸入若干個學生的成績,統計計算出平均成績,並輸出低於平均分的學生成績,輸入負數結束程序執行
從鍵盤上輸入若干個學生的成績,統計並輸出最高成績和最低成績,當輸入負數時,結束輸入。
#include<stdio.h>
void main(){
float x,amax,amin;
scanf("%f",&x);
amax=x;
amin=x;
while(x>=0)
{
if(x>amax)
amax=x;
if(x<amin)
amin=x;
scanf("%f",&x);
}
printf(" amax=%f amin=%f ",amax,amin);
}
(2)輸入若干個學生的若干個成績擴展閱讀:
①printf()函數是格式化輸出函數,一般用於向標准輸出設備按規定格式輸出信息。
格式輸出,它是c語言中產生格式化輸出的函數(在stdio.h中定義)。用於向終端(顯示器、控制台等)輸出字元。格式控制由要輸出的文字和數據格式說明組成。
要輸出的文字除了可以使用字母、數字、空格和一些數字元號以外,還可以使用一些轉義字元表示特殊的含義。
簡單點理解就是,在一段程序中你正確使用該函數,可以在該程序運行的時候輸出你所需要的內容。
②printf函數是一個標准庫函數,它的函數原型在頭文件「stdio.h」中。但作為一個特例,不要求在使用printf函數之前必須包含stdio.h文件。
printf()函數的調用格式為:printf("<格式化字元串>",<參量表>)。
其中格式化字元串用於指定輸出格式。格式控制串可由格式字元串和非格式字元串兩種組成。
3. 從鍵盤上輸入若干個學生的成績,計算平均成績,並輸出低於平均分的分值
程序如下
#include <stdio.h>
void main()
{
int i,n,s=0;
float ave;
int a[30];
printf("請輸入學生個數:");
scanf("%d",&n);
printf("請輸入學生成績:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
s+=a[i];
}
ave=(float)s/n;
printf("平均成績為:%.2f\n",ave);
printf("低於平均分回的有:\n");
for(i=0;i<n;i++)
if(a[i]<ave)
printf("%d ",a[i]);
printf("\n");
}
------------------------------
祝樓主取得好答成績
4. C語言 輸入若干個學生成績,輸入n表示結束.計算總成績。
inti;
intsum=0;
while(1)
{
scanf("%d",&i);
if(i==-1)
{
break;
}
sum+=i;
}
printf(" sum=%d",sum);
5. c語言:從鍵盤上輸入若干個學生的成績,當成績小於0時結束輸入.計算出平均成績,並輸出不及格的成績和人數
#include<stdio.h>
intmain(){
doublex;
doublea[100];
doublesum=0;
inti,tot=0,count=0;
scanf("%lf",&x);
while(x>=0){
sum+=x;
tot++;
if(x<60)a[count++]=x;
scanf("%lf",&x);
}
printf("%lf ",sum/(double)tot);
printf("Fail:%d ",count);
for(i=0;i<count;i++)
printf("%lf ",a[i]);
return0;
}
6. 從鍵盤上輸入若干個學生的成績
#include<stdio.h>
intmain()
{
floatx,max,min;
scanf("%f",&x);
max=x;
//min=();
min=x;
while(x>=0)
{
if(x>max)
max=x;
if(x<min)
min=x;
//scanf("%f",());
scanf("%f",&x);
}
printf(" Max=%f Min=%f ",max,min);
return0;
}
分別填 x &x
運行結內果容
7. 1.從鍵盤上輸入若干個學生的成績,以-1結束,求所有成績的平均分。要求用while語句完成。
#include "stdio.h"
#define N 4
main ()
{ float ave,sum;
int i,j,a[N];
printf ("please input number:");
for (i=0;i<N;i++)
scanf ("%d",&a[i]);
sum=0;ave=0;
for (i=0;i<N;i++){
if (a[i]==-1) break;
for (i=0;i<N;i++)
{
sum+=a[i];
ave=sum/N;
}
}
printf ("%f\n",ave);
return 0;
}
大體上是這樣子回的答
8. c語言題目,輸入若干個(由輸入的變數n確定)學生的成績(有效成績為0~100分,輸入無效成績則重新
#include"stdio.h"
intmain(intargc,char*argv[]){
intn,score,max,min,i;
printf("Entern(int0<n)... n=");
if(scanf("%d",&n)!=1||n<1){
printf("Inputerror,exit... ");
return0;
}
printf("Pleaseenterthe%dstudentsscore(s)(int0~)... ",n);
for(i=0;i<n;i++){
while(scanf("%d",&score)!=1||score<0||score>100){
printf("Inputerror,redo:");
fflush(stdin);
}
if(i==0)
max=min=score;
if(max<score)
max=score;
if(min>score)
min=score;
}
printf(" Thebestscoreis%d theworstscoreis%d ",max,min);
return0;
}
運行樣例:
9. C++語言求:從鍵盤輸入若干個學生的學習成績,然後統計出及格和不及格的人數分別是多少
#include<iostream>
usingnamespacestd;
intmain(void)
{
cout<<"請輸入成績,-1結束: ";
intt;
cin>>t;
intjige=0,bujige=0;
while(t!=-1)
{
if(t>=60)
jige++;
else
bujige++;
cin>>t;
}
cout<<"及格人數版為權:"<<jige
<<" 不及格人數為:"<<bujige<<" ";
return0;
}
10. c語言從鍵盤上輸入若干個學生的成績,統計並輸出其中的最高成績和最低成績,當輸入負數時結束輸入
① 代碼:
#include<stdio.h>
intmain(intargc,charconst*argv[])
{
doublescore,highest,lowest;
intn;
highest=-1;lowest=1000000000;
n=0;
while(1){
scanf("%lf",&score);
if(score<0.0)break;
if(highest<score)highest=score;
if(lowest>score)lowest=score;
n++;
}
printf("Total%d: ",n);
printf("Thehighestscoreis:%6.2f ",highest);
printf("Thelowestscoreis:%6.2f ",lowest);
return0;
}
② 運行:
1006092.580.550.8-1
Total5:
Thehighestscoreis:100.00
Thelowestscoreis:50.80