輸入一批學生成績
㈠ 怎樣用c語言while語句,從鍵盤輸入一批學生的成績,計算所有成績大於60分的平均值
思路:從鍵盤接收數據,以0為整批成績輸入的結束,對每一個成績進行判斷,將所內有大於60分的成績容求和.最後,算出平均分並輸出.
#include"stdio.h"
void main()
{
int j=0;
float scor=0,x;
while(1) {
scanf("%f",&x);
if(x==0) break;//以成績為0作為這批成績輸入的終止.
if(x>60) {scor=scor+x; j++;}
}
printf("大於60分的學生的平均分:%.2f",(scor/j));
}
㈡ 編寫程序,輸入一批學生的成績,遇負數表示輸入結束,要求統計並輸出各等級成績的學生個數
public static void main(String[] args) {
List<Float> list=new ArrayList<Float>();
student(list);
int A=0;
int P=0;
int F=0;
for(Float f:list){
if(f>=0 && f<=59){
F++;
}
if(f>=60 && f<=89){
P++;
}
if(f>=90){
A++;
}
}
System.out.println("A等級人數:"+A+"\n");
System.out.println("P等級人數:"+P+"\n");
System.out.println("F等級人數:"+F+"\n");
}
public static void student(List<Float> list){
try{
System.out.println("請輸入成績:");
BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));
float value=Float.valueOf(strin.readLine()==""?"0":strin.readLine());
if(value>=0){
list.add(value);
student(list);
}else{
return;
}
}catch (Exception e) {
}
}
很辛苦,網採納
㈢ C編程:輸入一批學生的成績(整數),輸出最高分。
#include<stdio.h>
int main()
{
int max=0,fen;
while(scanf("%d",&fen)==1)
{
if(fen<0)
break;
if(fen>max)
max=fen;
}
printf("%d\n",max);
return 0;
}
應該看得懂吧,覺得行請採納
㈣ 簡單C語言 鍵盤輸入一批學生的成績(以負數為結束標志),計算平均分
#include <stdio.h>
main()
{
double N,M,one;//one記錄每次輸入的成績,N記錄學生數,M記錄總分,使用double記錄允許分數為小專數
N=0;//學生數初始屬為0
M=0;//總分初始為0
scanf("%lf",&one);//讀入第一個成績,或表示結束的負數
while(one>=0)//直到讀入的數是負數時停止
{
N++;//人數加1
M=M+one;//總分加上該生分數
scanf("%lf",&one);//讀入下一個分數,或表示結束的負數
}
printf("總分:%.2lf\n",M);//輸出總分,保留兩位小數,(可通過改變.後的數字改變保留位數)
if(N>0)printf("平均分:%.2lf\n",M/N);//人數不為零,輸出平均分M/N,保留兩位小數
else printf("平均分:0\n");//人數,為零,輸出平均分0
}
㈤ c語言輸入一批學生成績,找出最高分
#include
<stdio.h>
#define
N
5 //通過改變宏定義,改變數組元素的個數
void
main()
{
int
a[N];
int
i;
int
max;
max=a[0];
printf("請輸入一組學生成績(假設有5位學生成績,且學生成績都是整數型)\n");
for(i=0;i<N;i++)
{
scanf("%d",&a[i]);
// printf("%f\n",a[i]);
}
for(i=0;i<N;i++)
{
if(max<a[i])
max=a[i];
}
printf("學生成績最高分為:%d\n",max);
}
//僅供參考
㈥ c語言……從鍵盤輸入一批學生的成績,當輸入一個負數時結束輸入,然後計算這批成績的總分和平均分
#include<stdio.h>
int main()
{ //首先,i因為是整數所以可以用整型,其他值可能出現小數所以用浮點型
//所有變數全部初專始化,屬否則編譯器可能會報錯
int i = 0;
float score = 0, sum = 0, aver = 0;
while (score >= 0) {
printf("請輸入成績(0--100), 其它值結束: ");
scanf("%f", &score);
if (score > 100) {
printf("Wrong input\n");
continue; //當輸入錯誤值時,為了不使錯誤值影響以後的計算,直接跳到循環開始
}
else if (score < 0)
continue; //當輸入score的值為負數時,跳過下一條else語句,同時退出循環,輸出結果
else {
sum += score; //將輸入的score累加
}
i++; //對每次循環計數,相當於對輸入的成績計數
}
aver = sum / i; //計算平均數
printf("sum: %f", sum);
printf("aver: %f", aver);
return 0;
}
㈦ 編寫一個C++程序是輸入一批學生的成績,計算該批學生的平均成績,並統計不及格學生人數
#include<stdio.h>
intmain()
{
intc,sc;
intsct=0,t=0;
printf("請輸入學生人數:");
scanf("%d",&c);
for(inti=1;i<=c;++i){
printf("請輸入第%d個學生成績:",i);
scanf("%d",&sc);
sct+=sc;
if(sc<60)t++;
}
doubleavg=sct*1.0/c;
printf("該批學版生的平均成績為權:%.1f 不及格學生人數為:%d ",avg,t);
return0;
}
㈧ 輸入一批學生成績,以-1作為結束標記(JAVA) 這句話是什麼意思 能舉例說明嗎
public class Test {
public static void main(String[] args) throws IOException {
Scanner scanner=new Scanner(System.in);//輸入類
double score=-1;//默認是-1
do {
System.out.println("輸入成績內:");
score= scanner.nextDouble();//讓用戶輸入,然後輸入的值,賦容給score
} while (score!=-1);//只有當score(即用戶輸入的值 )不為-1時才循環
}
}
運行效果如下:
輸入成績:
2
輸入成績:
3
輸入成績:
-1
㈨ 輸入一批學生成績,以-1作為結束標記
把int score=null;
改成
int score=-1;就行了
㈩ c++簡單編程題目 while循環 題目: 從鍵盤輸入一批以負數結束的學生成績,計算平均分
#include<iostream>
#include<iomanip>
usingnamespacestd;
intmain()
{
intscore,sum=0,count=0;
doubleaver;
cout<<"Entergrades:"<<endl;
while(cin>>score,score+1)
{
sum+=score;
答count++;
}
aver=sum*1.0/count;
cout<<"Gradeaverageis"<<setprecision(3)<<aver<<endl;
return0;
}