❶ c語言中學生信息的錄入功能
1。根據學生信息定義一個結構體類型,再說明一個該結構體類型的數組。*/
struct stu_info{
char stuNo[10];/* No */
char stuName[30];/* Name */
float stuScore[3];/* the three scores */
float aveScore; /* average score */
float totalScore; /* total score */
}stu[10];
/* 2。用input函數從鍵盤上輸入10個學生的數據。 */
void input()
{ int i = 0;
printf("Input the students' infomation(FORMAT LIKE:No Name score1 score2 score3):\n");
while(i < 10)
{ printf("Input %d:",i + 1);
scanf("%s%s%f%f%f",stu[i].stuNo,stu[i].stuName,&stu[i].stuScore[0],&stu[i].stuScore[1],&stu[i].stuScore[2]);
i++;
}
}
❷ C語言 1.用結構體類型和數組編程實現輸入學生姓名,性別,年齡,三門課程的成績,家庭住址。
#includestruct stud { int num; char name[30]; float score[3];} ;int main(){ struct stud stu ; int i; float avg ; printf("input number: "); scanf("%d", &stu.num ); printf("input name: " ); scanf("%s", stu.name ); printf("input 3 score:\n"); avg=0; for( i=0;i<3;i++ ) { scanf("%f", &stu.score[i] ); avg += stu.score[i] ; } avg /= 3 ; printf("average score: %f\n", avg ); return 0;}
❸ c語言怎麼編寫學生信息
#include "stdio.h"
#include <stdlib.h>
#define SIZE 10
struct student{
char id[20];
char sex[10];
int age;
int score[3];
float average;
} stud[SIZE];
void input() /* 輸入學生的信息 */
{
int i;
for(i=0;i<SIZE;i++)
{
printf("第%d個學生的信息:\n",i+1);
scanf("%s%s%d%d%d%d",stud[i].id,stud[i].sex,&stud[i].age,&stud[i].score[0],&stud[i].score[1],&stud[i].score[2]);
stud[i].average=(stud[i].score[0]+stud[i].score[1]+stud[i].score[2])/3.0;
}
}
void output() /* 輸出學生的信息 */
{
int i;
printf("\n");
for(i=0;i<SIZE;i++)
printf("%s %s %d %d %d %d %3.1f\n",stud[i].id,stud[i].sex,stud[i].age,stud[i].score[0],stud[i].score[1],stud[i].score[2],stud[i].average);
}
void sortput() /* 排序輸出學生信息 */
{
int i,j;
struct student temp;
for(i=0;i<SIZE;i++)
{
for(j=0;j<SIZE-i-1;j++)
{
if(stud[j].average<stud[j+1].average)
{
temp=stud[j];
stud[j]=stud[j+1];
stud[j+1]=temp;
}
}
}
printf("\n");
for(i=0;i<SIZE;i++)
printf("%s %s %d %d %d %d %3.1f\n",stud[i].id,stud[i].sex,stud[i].age,stud[i].score[0],stud[i].score[1],stud[i].score[2],stud[i].average);
}
void main()
{
input();
output();
sortput();
}
❹ 編寫一個c語言程序,實現錄入學生學號和姓名信息的功能
#include<stdio.h>
#include<stdlib.h>
intmain(void)
{
chars[10];//姓名
intnum;//學號
printf("請輸入姓名: ");
gets(s);
printf("請輸學號: ");
scanf("%d",&num);
printf("姓名是:%s 學號是:%d ",s,num);
system("pause");
return0;
}
(4)c語言輸入學生信息擴展閱讀
c語言建立學生檔案
#include<stdio.h>
#include<string.h>
結構學生
{
整數
字元名稱[10];
智
intEng;
墊子;
};
//s_number-檢索的學號
//numebr-文檔已經存儲的學號
//按學號查找
布爾搜索(chars_New[],charNew[])
{
如果(strcmp(s_New,New))
{
返回true;//查找成功
}
其他
{
returnfalse;//查找失敗
}
}
無效menu()
{
printf(「----------------------------------------------------------- 「);
printf(「菜單: 」);
printf(「 1。建立學生檔案 」);
printf(「 2。讀取所有學生記錄 」);
printf(「 3。在文件尾添加學生記錄 」);
printf(「 4。查詢學生姓名 」);
printf(「 5。結束程序 」);
printf(「----------------------------------------------------------- 「);
}
無效menu_2()
{
printf(「----------------------------------------------------------- 「);
printf(「查找選擇菜單: 」);
printf(「 1。按名字查找 」);
printf(「 2。按學號查找 」);
printf(「請選擇: 」);
printf(「----------------------------------------------------------- 「);
}
intmain()
{
而(1)
{
菜單();
法官
printf(「請輸入你的選項:」);
判斷=scanf(「%d」,&n);
如果(判斷==0)
{
printf(「輸入格式錯誤! 」);
}
開關(n)
{
情況1:
{
FILE*pf=fopen(「Student.txt」,「w+」);
字元標志='Y';
while(flag=='Y'|flag=='y')
{
學生stu;//創建學生結構體
printf(「請輸入學生的學號: 」);
scanf(「%d」,&stu.number);
getchar();//吃掉以上一個輸入的回車符
printf(「請輸入學生的姓名: 」);
scanf(「%s」,stu.name);
printf(「請輸入學生的語文成績: 」);
scanf(「%d」,&stu.Chi);
printf(「請輸入學生的英語成績: 」);
scanf(「%d」,&stu.Eng);
printf(「請輸入學生的數學成績: 」);
scanf(「%d」,&stu.Mat);
//把學生檔案導入Student.txt文檔
fprintf(pf,「#姓名:%s 學號:%d 語言成績:%d 英語成績:%d 數學成績:%d 」,stu.name,stu.number,stu.Chi,stu.Eng,stu.Mat);
getchar();//吃掉以上一個輸入的回車符
printf(「是否繼續輸入學生檔案?(是或否) 」);
判斷=scanf(「%c」,&flag);
如果(判斷==0)
{
printf(「輸入格式錯誤! 」);
}
}
fclose(pf);
打破;
}
❺ C語言 要求通過鍵盤輸入三個學生信息(包括姓名、學號、班級),並輸出這三個學生的所有信息。 結構體
#include<stdio.h>
struct st{//定義結構體
char name[20];
int id;
char _class[20];
};
int main()
{
struct st s[11];//定義結構體數組;
for(int i=0;i<3;i++)
scanf("%s%d%s",s[i].name,&s[i].id,s[i]._class);//輸入
for(int i=0;i<3;i++)
printf("姓名:%s 學號:%d 班級:%s ",s[i].name,s[i].id,s[i]._class);//輸出
}
❻ C語言 建立鏈表輸入學生信息然後輸出 哪裡錯了.
同意樓上,還有一個地方有點小問題,您本身的意思是想如果輸入的數大於10,要重新輸入,但實際上如果輸入大於10的數,程序並沒有要求再次輸入length的大小,是因為少了一對大括弧,應該這樣:
if(length<10)
{
flag=0;
for(i=0;i
評論
0
0
載入更多
❼ C語言輸入學生信息
scanf裡面的空格與/去掉
❽ C語言在鍵盤上輸入三個學生的信息(包含學號,姓名,三門課的成績)並在顯示器上輸
id, name, &m1
id, name, m1
voidprintScore(intscore[4][3])
{inti,j;for(i=0;i<4;i++)
{printf("學生%d的三門成績分別為:
",i+1);for(j=0;j<3;j++)
{printf("%d ",score<i>[j]);
if(j==2)printf(" ");}}printf(" ");}
printf()函數是格式化輸出函數,一般用於向標准輸出設備按規定格式輸出信息。格式輸出,它是c語言中產生格式化輸出的函數(在stdio.h中定義)。
函數介紹
printf()函數是格式化輸出函數,一般用於向標准輸出設備按規定格式輸出信息。在編寫程序時經常會用到此函數。函數的原型為:intprintf(constchar*format);
函數返回值為整型。若成功則返回輸出的字元數,輸出出錯則返回負值。
printf()函數的調用格式為:printf("<格式化字元串>",<參量表>);其中格式化字元串包括兩部分內容:一部分是正常字元,這些字元將按原樣輸出;另一部分是格式化規定字元,以"%"開始,後跟一個或幾個規定字元,用來確定輸出內容格式。
以上內容參考:網路-printf()
❾ 求用C語言怎麼實現學生信息錄入功能
* 1。根據學生信息定義一個結構體類型,再說明一個該結構體類型的數組。*/
struct stu_info{
char stuNo[10];/* No */
char stuName[30];/* Name */
float stuScore[3];/* the three scores */
float aveScore; /* average score */
float totalScore; /* total score */
}stu[10];
/* 2。用input函數從鍵盤上輸入10個學生的數據。 */
void input()
{ int i = 0;
printf("Input the students' infomation(FORMAT LIKE:No Name score1 score2 score3):\n");
while(i < 10)
{ printf("Input %d:",i + 1);
scanf("%s%s%f%f%f",stu[i].stuNo,stu[i].stuName,&stu[i].stuScore[0],&stu[i].stuScore[1],&stu[i].stuScore[2]);
i++;
}
}
❿ C語言 從鍵盤輸入10個學生信息(學號,姓名,年齡,性別)
#include<stdio.h>
void main()
{
struct
{
char name[10];
int num;
char sex[2];
int age;
}s[10];
int i;
for(i=0;i<10;i++)
{
printf("請依次輸入學生的姓名,學號,性別,年齡等信息");
scanf("%s%d%s%d",s[i].name,&s[i].num,s[i].sex,&s[i].age);
}
for(i=0;i<10;i++)
{
printf("姓名:%s 學號:%d 性別:%s 年齡:%d ",s[i].name,s[i].num,s[i].sex,s[i].age);
}
}
(10)c語言輸入學生信息擴展閱讀:
在C語言中,結構體(struct)指的是一種數據結構,是C語言中聚合數據類型(aggregate data type)的一類。結構體可以被聲明為變數、指針或數組等,用以實現較復雜的數據結構。
結構體同時也是一些元素的集合,這些元素稱為結構體的成員(member),且這些成員可以為不同的類型,成員一般用名字訪問。定義與聲明
結構體的定義如下,struct為結構體關鍵字,tag為結構體的標志,member-list為結構體成員列表,其必須列出其所有成員;variable-list為此結構體聲明的變數。
作用:
1,結構體和其他類型基礎數據類型一樣,例如int類型,char類型 只不過結構體可以做成你想要的數據類型。以方便日後的使用。
2,在實際項目中,結構體是大量存在的。研發人員常使用結構體來封裝一些屬性來組成新的類型。由於C語言內部程序比較簡單,研發人員通常使用結構體創造新的「屬性」,其目的是簡化運算。
3,結構體在函數中的作用不是簡便,其最主要的作用就是封裝。
參考資料來源:網路-結構體