จงเขียนโปรแกรมรับคะแนนของนักเรียน 3 คน ซึ่งลงทะเบียนทั้งหมด 5 วิชาคือ Mathematics,English,Chemical,PhysicalและComputer โดยให้ใช้ ฟังก์ชั่น scanf() รับค่าคะแนนเข้ามาได้เพียง 1 ครั้งต่อนักเรียน 1 คนเท่านั้น ดังนั้นมีนักเรียน 3 คนจึงสามารถใช้ฟังก์ชั่น scanf() ได้เพียง 3 ครั้งเท่านั้นจากนั้นทำการหาคะแนนรวม 5 วิชาของนักเรียนแต่ละคน แล้วแสดงออกทางจอภาพ
วิธีทำ
#include
main()
{
int std1_math,std1_eng,std1_chem,std1_phy,std1_com;
int std2_math,std2_eng,std2_chem,std2_phy,std2_com;
int std3_math,std3_eng,std3_chem,std3_phy,std3_com;
printf("Please input score in same line order by subject\n");
printf("Subject => Mathematics English Chemical Physical Computer\n");
printf("For example => student A : 50 60 70 80 90\n");
printf("Student 1 :");
scanf("%d %d %d %d %d",&std1_math,&std1_eng,&std1_chem,&std1_phy,&std1_com);
printf("Student 2 :");
scanf("%d %d %d %d %d",&std2_math,&std2_eng,&std2_chem,&std2_phy,&std2_com);
printf("Student 3 :");
scanf("%d %d %d %d %d",&std3_math,&std3_eng,&std3_chem,&std3_phy,&std3_com);
printf("\nTotal score\n");
printf("Student1 : %d\n",std1_math+std1_eng+std1_chem+std1_phy+std1_com);
printf("Student2 : %d\n",std2_math+std2_eng+std2_chem+std2_phy+std2_com);
printf("Student3 : %d\n",std3_math+std3_eng+std3_chem+std3_phy+std3_com);
}
แบบฝึกพื้นฐานนะเพื่อนๆ ถ้าไม่เข้าใจส่วนไหนถามมาได้เลย :)
ตอบลบอันนี้ดูยากจังเนอะT_T
ตอบลบกี้ ตงinclude วงเล็บหายเหมือนเราอ่ะ TT
ตอบลบโห โค๊ดสุดยอดเลย ยาวจัง แต่เก่งมากๆเลย
ตอบลบยาวมากกก!!!
ตอบลบลึกซึ้ง แบบว่าได้เพื่อนคนนี้มาสอนเข้าใจแบบสุดๆ
ตอบลบเข้าใจแล้วจร้า include เราก็เป็นนะ
ตอบลบอ๋อออ กำหนดตัวแปลโดยใช้ int ทีเดียวเลยได้อะจิ
ตอบลบ