Name: Phalla Sophorndara
Exercise
1. Variable ជាកន្លែងសម្រាប់ផ្ទុកទិលនល័យ។
Control statement អាចអអាយអយើងបញ្ចូលអៅstructឬLoop។
Loop statement ជាការកំណត់អអាយCode អដើរដន្ដលៗ មិលឈប់។
Function ជាBlock Code សម្រាប់អៅអេលម្រតូវការវា លិងអ្វើការជាក់លាក់។
2. Array ជាការអម្របើរកសាតម្មែអម្រចើលកនុងអអេរមួយ ជំលួសអអាយការម្របកាសអអេរដាច់អដាយន្ែកសម្រាប់
តម្មែលីមួយៗ។
លំហាត់អលុវតតល៍
១.#include<stdio.h>
int main()
int code;
char name[20];
int qty;
double price;
float total;
float payment;
int discount;
printf("Input Code : \n");
scanf("%d",&code);
printf("Input name : \n");
scanf("%s",&name);
printf("Input qty : \n");
scanf("%d",&qty);
printf("Input price : \n");
scanf("%lf$",&price);
printf("Input discount: \n");
scanf("%d",&discount);
total= qty*price;
printf("==============================================\n");
if(total>1 && total<=10)
discount=10;
else if(total>10 && total<=20)
discount=20;
else if(total>20 && total<=30)
discount=30;
else if(total>30 && total<=40)
discount=40;
else if(total>40 && total<=50)
discount=50;
else if(total>50 && total<=60)
discount=60;
else
discount=70;
payment=total-total*discount/100;
printf("==============================================\n");
printf("Code :%d\n",code);
printf("name :%s\n",name);
printf("qty :%d\n",qty);
printf("price :%.2lf$\n",price);
printf("discount :%d\n",discount);
printf("total :%.2lf$\n",total);
printf("payment :%.2lf$\n",payment);
return 0;
}
3. Pointer អម្របើសម្រាប់រកសាទុកអអេរ។
Structure អម្របើសម្រាប់ដាក់អអេរជាអម្រចើលន្ដលពាក់ពាល់គ្នាអៅកន្លែងមួយ។
4.Exercise Structure
#include<stdio.h>
struct student{
int id;
char name[30];
float Crograming;
float Math;
float English;
float Fundamental;
float khmerHistory;
float Economy;
float Average;
float total;
char grade[30];
int year;
char class[30];
};
int main()
int n, i;
printf("Please Enter Number Student \n");
scanf("%d",&n);
struct student stu[n];
for(i=0;i<n;i++){
printf("\n=============================\n");
fflush(stdin);
printf("Enter ID :");
scanf("%d", stu[n].id);
printf("Enter Name :");
scanf("%s", stu[i].name);
printf("Enter Cprogram :");
scanf("%.2lf",stu[i].Crograming);
printf("Enter Math :");
scanf("%.2lf",stu[i].Math);
printf("Enter English :");
scanf("%.2lf",stu[i].English);
printf("Enter Fundamental :");
scanf("%.2lf",stu[i].Fundamental);
printf("Enter khmerHistory :");
scanf("%.2lf",stu[i].khmerHistory);
printf("Enter Economy :");
scanf("%.2lf",stu[i].Economy);
stu[i].total = stu[i].Crograming + stu[i].Economy +stu[i].English +
stu[i].Fundamental+stu[i].khmerHistory + stu[i].Math;
stu[i].Average= stu[i].total/3.0;
return 0;