『壹』 c語言程序設計
#include<stdio.h>
struct student /*定義一個學生類型結構體*/
{
long num;
char name[20];
float score1;
float score2;
float score3;
float total;
float aver;
};
main()
{
void input(struct student t[3]);/*定義input函數,輸入學生信息*/
void average(struct student v[3]);/*定義average函數,求每個學生總成績、平均成績和所有學生的總平均成績*/
void maximum(struct student r[3]);/*定義maximum函數,找出最高分的學生的數據*/
struct student s[3];
int i;
input(s);
printf("the information of student is:\n");
printf("num name score1 score2 score3 total aver\n");
for(i=0;i<3;i++)
printf("%ld %s %f %f %f %f %f\n",s[i].num,s[i].name,s[i].score1,s[i].score2,s[i].score3,s[i].total,s[i].aver);
average(s);
maximum(s);
printf("the information of student with the highest total score is:\n");
printf("%s %f\n",s[0].name,s[0].total);
}
void input(struct student t[3])
{
int i;
printf("please input student's information:\n");
for(i=0;i<3;i++)
{t[i].total=0;
t[i].aver=0;
scanf("%ld%s%f%f%f",&t[i].num,&t[i].name,&t[i].score1,&t[i].score2,&t[i].score3);
t[i].total=t[i].score1+t[i].score2+t[i].score3;
t[i].aver=t[i].total/3;
}
}
void average(struct student v[3])
{
int i;
float sum=0,average=0;
for(i=0;i<3;i++)
{v[i].total=v[i].score1+v[i].score2+v[i].score3;
v[i].aver=v[i].total/3;
sum+=v[i].aver;}
average=sum/3;
printf("the average score of all the students is :average=%f\n",average);
}
void maximum(struct student r[3])
{
int i;
float t;
for(i=0;i<3;i++)
if(r[i].total>r[0].total)
{t=r[0].total;
r[0].total=r[i].total;
r[i].total=t;
strcpy(r[0].name,r[i].name);
r[0].num=r[i].num;r[0].score1=r[i].score1;r[0].score2=r[i].score2;r[0].score3=r[i].score3;
r[0].aver=r[i].aver;
}/*將所有學生信息進行排序,總分高的放在第一組,輸出時只需輸出第一組學生信息*/
}
程序中限定了學生個數為3,要改成10,則需將3替換為10。運行結果如下:
please input student's information:
1061 lili 80 78 98
1062 liujun 85 80 92
1063 guowei 82 83 93
the information of student is:
num name score1 score2 score3 total aver
1061 lili 80.000000 78.000000 98.000000 256.000000 85.333336
1062 liujun 85.000000 80.000000 92.000000 257.000000 85.666664
1063 guowei 82.000000 83.000000 93.000000 258.000000 86.000000
the average score of all the students is :average=85.666664
the information of student with the highest total score is:
guowei 258.000000
第二題不會。
『貳』 c語言如何入門
既然已經學過C語言,就算入門了。再學習應該算是再入門了,哈哈。
找一門譚浩強的書快速看一遍,然後,根據你的實際情況,用C語言寫幾個小一點的程序,然後寫寫幾個稍微大一點的程序就可以了。
如果想要精通C語言,那就要看好多C語言的書,譬如C語言高級程序設計等等。
還有一個最直接的方法,看一遍書,做完題,然後再網路知道上,搜索所有與C有關的提問,然後自己總結,最後形成一個比較大的文檔,到時你就是一個C語言專家了!!
網路編程方面的書就多了,你是做安全,還是做頁面展示,做不同的東東,需要不同的學習書籍,如果做展示,可以按下述步驟學習:
1、html
2、css
3、javascript(類C語言)
4、php(jsp,asp,java,.net)
5、資料庫(access,mysql,sqlserver,oracle)
6、一些常用工具(photoshop,flash,word)
等等。
『叄』 C語言的類怎麼定義
C++才有類,用class關鍵字定義。