成績問題c語言,C語言成績判斷

本文目錄一覽:

c語言,成績統計問題

你好!

avergae ,程序後面的 avergae 拼寫錯了,修改後的:

#includestdio.h

int main()

{

 int i,max,sum=0;

 float avergae;

 int a[10];

 for(i=1;i=9;i++)

 {

  scanf(“%d”,a[i]);

  sum+=a[i];

 }

 max=a[0];

 for(i=1;i=9;i++)

 {

  if(a[i]max)

  {

   max=a[i];

  }

 }

 avergae=sum/10.0;

 if(a[i]avergae)

 printf(“%d,%f,%d”,max,avergae,a[i]);

 printf(“\n”);

}

學生成績處理問題(c語言)

#include stdio.h

#include stdlib.h

#include string.h

struct STUDENT{

    float score[3];

    long id;

    char names[20];

};

typedef struct STUDENT student;//simplify the struct STUDENT

typedef struct STUDENT *Pstudent;

     

void print();

void append();

void course_total();

void student_total();

void score_sort(int (*compare)(float a,float b));

void number_sort();

void name_sort(Pstudent names_[30]);

void number_search();

void name_search();

void statistic(Pstudent scores_[30]);

     

void show(int i);

     

int ascend(float a, float b){

    if(ab) return 1;

    else  return 0;

}

int descend(float a, float b){

    if(ab)  return 1;

    else  return 0;

}

int n;//the number of students

     

int flg=1;//true print the result

student *stuArray[30];//the global variable can simplify the compute

     

int again=1;//whether to continue

int main(){

    int i;

    printf(“Input student number(n30):”);

    scanf(“%d”,n);

    int choice;

    while(again){

        print();

        scanf(“%d”,choice);

        switch(choice){

            case 1:

                append();

                break;

            case 2:

                course_total();//use flag to define whether to print

                break;

            case 3:

                student_total();

                break;

            case 4:

                score_sort(descend);

                if(flg){

                    printf(“Sort in descending order by total score of every student:\n”);

                    printf(“NO\tName\tMT\tEN\tPH\tSUM\tAVER\n”);

                    for(i=0;in;i++)

                        show(i);

                }

                break;

            case 5:

                score_sort(descend);

                if(flg){

                    printf(“Sort in ascending order by total score of every student:\n”);

                    printf(“NO\tName\tMT\tEN\tPH\tSUM\tAVER\n”);

                    for(i=0;in;i++)

                        show(n-1-i);

                }

                break;

            case 6:

                number_sort();

                break;

            case 7:

                name_sort(stuArray);

                break;

            case 8:

                number_search();

                break;

            case 9:

                name_search();

                break;

            case 10:

                statistic(stuArray);

                break;

            case 0:

                again=0;

                printf(“End of program!\n”);

                break;

            default:

                printf(“Input error!\n”);

                break;

        }

     

    }

return 0;

}

     

void print(){

    printf(“1.Append record\n”);

    printf(“2.Calculate total and average score of every course\n”);

    printf(“3.Calculate total and average score of every student\n”);

    printf(“4.Sort in descending order by total score of every student\n”);

    printf(“5.Sort in ascending order by total score of every student\n”);

    printf(“6.Sort in ascending order by number\n”);

    printf(“7.Sort in dictionary order by name\n”);

    printf(“8.Search by number\n”);

    printf(“9.Search by name\n”);

    printf(“10.Statistic analysis\n”);

    printf(“Please Input your choice:”);

}

void append(){

    int i;

    printf(“Input student’s ID,name and score:\n”);

    for(i=0;in;i++){////the most significant part malloc the memory when appending record

        stuArray[i] = (student *)malloc(sizeof(student));

        scanf(“%ld%s”,stuArray[i]-id,stuArray[i]-names);

        scanf(“%f”,stuArray[i]-score[0]);

        scanf(“%f”,stuArray[i]-score[1]);

        scanf(“%f”,stuArray[i]-score[2]);

    }

}

void course_total(){

    int i;

    float sum0=0.0,sum1=0.0,sum2=0.0;

    for(i=0;in;i++){

        sum0+=stuArray[i]-score[0];

        sum1+=stuArray[i]-score[1];

        sum2+=stuArray[i]-score[2];

    }

    if(flg){

        printf(“course %d:sum=%.0f,aver=%.0f\n”,1,sum0,sum0/n);

        printf(“course %d:sum=%.0f,aver=%.0f\n”,2,sum1,sum1/n);

        printf(“course %d:sum=%.0f,aver=%.0f\n”,3,sum2,sum2/n);

    }

}

void student_total(){

    float total[30]={0.0};

    int i;

    for(i=0;in;i++){

        total[i]=stuArray[i]-score[0]+stuArray[i]-score[1]+stuArray[i]-score[2];

    }

    if(flg){

        for(i=0;in;i++)

            printf(“student %d:sum=%.0f,aver=%.0f\n”,i+1,total[i],total[i]/3);

    }

}

void score_sort(int (*compare)(float a,float b)){

    int i,j;

    float total[30]={0.0};

    for(i=0;in;i++){

        total[i]=stuArray[i]-score[0]+stuArray[i]-score[1]+stuArray[i]-score[2];

    }

    for(i=0;in;i++){

        for(j=0;j=i;j++)

            //if((*compare)(stuArray[i]-score[0]+stuArray[i]-score[1]+stuArray[i]-score[2],stuArray[j]-score[0]+stuArray[j]-score[1]+stuArray[j]-score[2])==0){

            if((*compare)(total[i],total[j])==0){//just swap the pointer it simplify the program

                  student *tmp=(student *)malloc(sizeof(student));

                  memcpy(tmp,stuArray[i],sizeof(student));

                  memcpy(stuArray[i],stuArray[j],sizeof(student));

                  memcpy(stuArray[j],tmp,sizeof(student));

        }//memcpy- copy the hole the memory

    }

     

}

void number_sort(){//沒必要傳參

    int i,j;

    for(i=0;in;i++){

        for(j=0;ji;j++)

            if(stuArray[i]-idstuArray[j]-id){

                  student *tmp=(student *)malloc(sizeof(student));

                  memcpy(tmp,stuArray[i],sizeof(student));

                  memcpy(stuArray[i],stuArray[j],sizeof(student));

                  memcpy(stuArray[j],tmp,sizeof(student));

            }

    }

    if(flg){

        printf(“Sort in ascending order by number:\n”);

        printf(“NO\tName\tMT\tEN\tPH\tSUM\tAVER\n”);

        for(i=0;in;i++)

            show(i);

    }

}

void name_sort(Pstudent names_[30]){

    int i,j;

    for(i=0;in;i++){

        for(j=0;j=i;j++)

            if(strcmp(names_[i]-names,names_[j]-names)0){

                  student *tmp=(student *)malloc(sizeof(student));

                  memcpy(tmp,stuArray[i],sizeof(student));

                  memcpy(stuArray[i],stuArray[j],sizeof(student));

                  memcpy(stuArray[j],tmp,sizeof(student));

            }

    }

    if(flg){

        printf(“Sort in dictionary order by name:\n”);

        printf(“NO\tName\tMT\tEN\tPH\tSUM\tAVER\n”);

        for(i=0;in;i++)

            show(i);

    }

}

void number_search(){

    long query;

    printf(“Input the number you want to search:”);

    scanf(” %ld”,query);

    int i;

    score_sort(descend);//100 98 87

    for(i=0;in;i++){

        if(stuArray[i]-id==query)

            break;

    }

    if(i!=n){

        printf(“%d\t”,i+1);

        show(i);

    }

    else

        printf(“Not found!\n”);

}

void name_search(){

    char query[20];

    score_sort(descend);

    printf(“Input the name you want to search:”);

    scanf(“%s”,query);

    int i;

    for(i=0;in;i++){

        if(!strcmp(query,stuArray[i]-names)){

            break;

        }

    }

    if(i!=n){

        printf(“%d\t”,i+1);

        show(i);

    }

    else

        printf(“Not found!\n”);

}

void statistic(Pstudent scores_[30]){//a pointer array stands for scores

    float MT[30],EN[30],PH[30];

    int i;

    for(i=0;in;i++){

        MT[i]=scores_[i]-score[0];

        EN[i]=scores_[i]-score[1];

        PH[i]=scores_[i]-score[2];

    }

    int sta[6]={0};//means the statistic of every student (60 or 60-70 ….)

    for(i=0;in;i++){

        if(MT[i]60)

            sta[0]++;

        if(MT[i]==100)

            sta[5]++;

        if(MT[i]=60MT[i]=69)

            sta[1]++;

        if(MT[i]=70MT[i]=79)

            sta[2]++;

        if(MT[i]=80MT[i]=89)

            sta[3]++;

        if(MT[i]=90MT[i]=100)

            sta[4]++;

    }

     

    if(flg){

        printf(“For course %d:\n”,1);

        printf(“60\t%d\t%.2f%%\n”,sta[0],sta[0]/(float)n*100);//change n to float

        printf(“60-69\t%d\t%.2f%%\n”,sta[1],sta[1]/(float)n*100);

        printf(“70-79\t%d\t%.2f%%\n”,sta[2],sta[2]/(float)n*100);

        printf(“80-89\t%d\t%.2f%%\n”,sta[3],sta[3]/(float)n*100);

        printf(“90-100\t%d\t%.2f%%\n”,sta[4],sta[4]/(float)n*100);

        printf(“100\t%d\t%.2f%%\n”,sta[5],sta[5]/(float)n*100);

    }

    memset(sta,0,6*sizeof(int));//initialize the sta array

    for(i=0;in;i++){

        if(EN[i]60)

            sta[0]++;

        if(EN[i]==100)

            sta[5]++;

        if(EN[i]=60EN[i]=69)

            sta[1]++;

        if(EN[i]=70EN[i]=79)

            sta[2]++;

        if(EN[i]=80EN[i]=89)

            sta[3]++;

        if(EN[i]=90EN[i]=100)

            sta[4]++;

    }

     

    if(flg){

        printf(“For course %d:\n”,2);

        printf(“60\t%d\t%.2f%%\n”,sta[0],sta[0]/(float)n*100);//change n to float

        printf(“60-69\t%d\t%.2f%%\n”,sta[1],sta[1]/(float)n*100);

        printf(“70-79\t%d\t%.2f%%\n”,sta[2],sta[2]/(float)n*100);

        printf(“80-89\t%d\t%.2f%%\n”,sta[3],sta[3]/(float)n*100);

        printf(“90-100\t%d\t%.2f%%\n”,sta[4],sta[4]/(float)n*100);

        printf(“100\t%d\t%.2f%%\n”,sta[5],sta[5]/(float)n*100);

    }

    memset(sta,0,6*sizeof(int));

    for(i=0;in;i++){

        if(PH[i]60)

            sta[0]++;

        if(PH[i]==100)

            sta[5]++;

        if(PH[i]=60PH[i]=69)

            sta[1]++;

        if(PH[i]=70PH[i]=79)

            sta[2]++;

        if(PH[i]=80PH[i]=89)

            sta[3]++;

        if(PH[i]=90PH[i]=100)

            sta[4]++;

    }

     

    if(flg){

        printf(“For course %d:\n”,3);

        printf(“60\t%d\t%.2f%%\n”,sta[0],sta[0]/(float)n*100);//change n to float

        printf(“60-69\t%d\t%.2f%%\n”,sta[1],sta[1]/(float)n*100);

        printf(“70-79\t%d\t%.2f%%\n”,sta[2],sta[2]/(float)n*100);

        printf(“80-89\t%d\t%.2f%%\n”,sta[3],sta[3]/(float)n*100);

        printf(“90-100\t%d\t%.2f%%\n”,sta[4],sta[4]/(float)n*100);

        printf(“100\t%d\t%.2f%%\n”,sta[5],sta[5]/(float)n*100);

    }

}

     

void show(int i){

     

    printf(“%ld\t%s\t”,stuArray[i]-id,stuArray[i]-names);//order is the id after sort

    printf(“%.0f\t%.0f\t%.0f\t”,stuArray[i]-score[0],stuArray[i]-score[1],stuArray[i]-score[2]);

    float sum=stuArray[i]-score[0]+stuArray[i]-score[1]+stuArray[i]-score[2];

    printf(“%.0f\t%.0f\n”,sum,sum/3);

}

用C語言編寫一個程序,輸入一個成績,判斷該成績是否及格。

#include “stdio.h”

int main()

{

int score;

printf(“請輸入一個成績:”);

scanf(“%d”,score);

if(score60  score=100)

printf(“成績合格\n”);

else if(score60  score=0)

printf(“成績不合格\n”);

else

printf(“輸入的成績有誤\n”);

}

C語言編程 關於成績的問題

include”stdio.h”

main( )

{

char a1;

scanf(“%c”,a1);

if(a1=’a’||a1=’A’||a1=’b’||a1=’A’)

prinf(“s”,「良好」);

else if(a1=’c’||a1=’C’||a1=’d’||a1=’D’)

printf(“s”,「及格」);

printf(”s”,「不及格」);

}

必須說明:我剛申請的這個東西,而且我對C、c++也是初學者。開始沒看到底下有高手答了已經,獻醜了,我可能不對,這是我自己編的第二個程序,初學者,,不要笑我,謝謝!

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/295287.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-26 17:15
下一篇 2024-12-26 17:15

相關推薦

  • Python官網中文版:解決你的編程問題

    Python是一種高級編程語言,它可以用於Web開發、科學計算、人工智慧等領域。Python官網中文版提供了全面的資源和教程,可以幫助你入門學習和進一步提高編程技能。 一、Pyth…

    編程 2025-04-29
  • 如何解決WPS保存提示會導致宏不可用的問題

    如果您使用過WPS,可能會碰到在保存的時候提示「文件中含有宏,保存將導致宏不可用」的問題。這個問題是因為WPS在默認情況下不允許保存帶有宏的文件,為了解決這個問題,本篇文章將從多個…

    編程 2025-04-29
  • AES加密解密演算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密演算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES演算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演著非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • Python輸入姓名成績輸出等級

    在這個項目中,我們需要輸入一個學生的姓名和成績,然後根據成績給出等級。 一、獲取用戶輸入 首先,我們需要獲取用戶輸入的姓名和成績。可以使用Python中的input()函數,讓用戶…

    編程 2025-04-29
  • Java Thread.start() 執行幾次的相關問題

    Java多線程編程作為Java開發中的重要內容,自然會有很多相關問題。在本篇文章中,我們將以Java Thread.start() 執行幾次為中心,為您介紹這方面的問題及其解決方案…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python爬蟲亂碼問題

    在網路爬蟲中,經常會遇到中文亂碼問題。雖然Python自帶了編碼轉換功能,但有時候會出現一些比較奇怪的情況。本文章將從多個方面對Python爬蟲亂碼問題進行詳細的闡述,並給出對應的…

    編程 2025-04-29
  • NodeJS 建立TCP連接出現粘包問題

    在TCP/IP協議中,由於TCP是面向位元組流的協議,發送方把需要傳輸的數據流按照MSS(Maximum Segment Size,最大報文段長度)來分割成若干個TCP分節,在接收端…

    編程 2025-04-29

發表回復

登錄後才能評論