Вы находитесь на странице: 1из 6

#include <stdio.

h>
#include <math.h>
int sep_2011_2ci ()
{
int i, p=30;
for(i=5;i>0;i--)
{
p=p-2;
printf("%d\n",p);
if(p%4==0)
printf("OK\n");
}
return 0;
}
int sep_2011_2cii ()
{
int i, m, p;
m=5;
for(i=1;i<=3;i++)
{
p=m-2;
m=m+p;
p+=6;
if(m>p)
printf("%d\n",p);
else
printf("%d\n",m);
}
printf("%d,%d\n",m,p);
return 0;
}
int sep_2011_4a (void)
{
int num1,num2,result;
printf("Please enter num1:");
scanf("%d",&num1);
printf("Please enter num2:");
scanf("%d",&num2);
if (num1>num2)
{
result=num1-num2;
printf("Subtraction result is %d\n",result);
}
else
{
result=num2-num1;
printf("Subtraction result is %d\n",result);
}
return 0;
}
int sep_2011_4b (void)
{
int stud_cnt=1;
float stud_score;
int num_a=0,num_b=0,num_c=0,num_d=0,num_f=0;
for(stud_cnt=1;stud_cnt<=10;stud_cnt++)
{
printf("Please enter student %d score:",stud_cnt);
scanf("%f",&stud_score);
if (stud_score>=90 && stud_score<=100)
num_a++;
else
if (stud_score>=78 && stud_score<=89)
num_b++;
else
if (stud_score>=65 && stud_score<=77)
num_c++;
else
if (stud_score>=50 && stud_score<=64)
num_d++;
else
num_f++;
}
printf("Total A:%d\nTotal B:%d\nTotal C:%d\nTotal D:%d\nTotal F:
%d\n",num_a,num_b,num_c,num_d,num_f);
return 0;
}
int sep_2017_2b (void)
{
int i=0,k=3,j,m,loop_count=5;
printf("Output 1:\n");
for(i=0;i<loop_count;i++)
{
i++;
printf("%d\n",i);
}
printf("Output 2:\n");
for(j=7;j>0;j--)
{
m=j+k;
printf("%d\n",m);
k--;
}
return 0;
}
int sep_2017_2c ()
{
int a=2,b=4,c=6,d=8,e,f,g,h,i;
printf("i)%d\n",e=(c+2)/8*3+d);
printf("ii)%d\n",f=a+d/4%a);
printf("iii)%d\n",g=++d*b++-4);
printf("iv)%d\n",h=-c*(10-a)/48-b--*3);
printf("v)%d\n",i=b*b+a-2*c);
return 0;
}
int sep_2017_3b (void)
{
float amount;
int x;
printf("Key in amount to save >> RM");
scanf("%f",&amount);
printf("\n");
for(x=1;x<=10;x++)
{
if (x>1)
{
printf("Year %d = RM%.2f",x,amount=amount*1.04);
printf("\n");
}
else
printf("Year 1 = RM%.2f\n",amount);
}
return 0;
}
int sep_2017_4b (void)
{
float total=0.0, price;
char code;
printf("Please enter code: ");
scanf("%c",&code);
fflush(stdin);
while (code!='Q')
{
printf("Please enter price: RM ");
scanf("%f",&price);
fflush(stdin);
printf("\n");
switch (code)
{
case 'H':
total+=price*0.5;
break;
case 'P':
total+=price*0.8;
break;
case 'Z':
total+=price;
}
printf("Please enter code: ");
scanf("%c",&code);
}
printf("Total: RM %.2f",total);
return 0;
}
int sep_2017_5a (void)
{
int x,y;
for(y=1;y<=6;y++)
{
for(x=1;x<=7-y;x++)
{
if (y==1)
printf("%d",y+5);
else
if (y==2)
printf("%d",y+3);
else
if (y==3)
printf("%d",y+1);
else
if (y==4)
printf("%d",y-1);
else
if (y==5)
printf("%d",y-3);
else
printf ("%d",y-5);
}
printf("\n");
}
return 0;
}
int sep_2017_5b (void)
{
int num, power,a;
do
{
printf("Enter a number: ");
scanf("%d",&num);
printf("Enter power: ");
scanf("%d",&power);
a=pow((float)num,power);
printf("Answer: %d\n\n",a);
}while (num!=0);
return 0;
}
int sep_2017_6a (void)
{
int amount,num_10=0,num_20=0,num_50=0,num_100=0;
printf("Please enter an amount RM (0 to exit)>>");
scanf("%d",&amount);
while(amount!=0)
{
if (amount%10==0)
{
printf("Number of pieces of notes according to the
denomination are:\n");
num_100+=amount/100;
amount%=100;
num_50+=(int)(amount/50);
amount%=50;
num_20+=(int)(amount/20);
amount%=20;
num_10+=(int)(amount/10);
printf("RM100: %d\nRM 50: %d\nRM 20: %d\nRM 10:
%d\n\n",num_100,num_50,num_20,num_10);
}
else
{
printf("Error: Please enter an amount divisible by
10.\n\n");
}
printf("Please enter an amount RM (0 to exit)>>");
scanf("%d",&amount);
}
if (amount==0)
printf("Ending program\n");
return 0;
}
int sep_2017_6b (void)
{
int x,y;
for(y=1;y<=5;y++)
{
for(x=1;x<=y;x++)
{
if (x==1)
printf("*");
if (x>=2 && x==y)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
int sep_2016_5a (void)
{
int x,y;
for(y=1;y<=5;y++)
{
for(x=1;x<=5;x++)
{
if (y==(6-x))
printf("%d",y);
else
printf("*");
}
printf("\n");
}
return 0;
}
int sep_2016_6 (void)
{
char reset;
int price,year,salary;
do
{
printf("Please key in the price of the car: RM");
scanf("%d",&price);
printf("Please key in the payback years: ");
scanf("%d",&year);
printf("Please key in your salary net pay: RM");
scanf("%d",&salary);
printf("\n");
if (year<=5)
printf("The monthly installment will be RM%.2f",(price*1.029)/
(year*12));
else
if (year>=6 && year<=7)
printf("The monthly installment will be RM%.2f",
(price*1.03)/(year*12));
else
if (year>7)
printf("The monthly installment will be RM%.2f",
(price*1.0315)/(year*12));
printf("\n\n");
if ((price*1.0315)/(year*12)>(salary/3))
printf("Sorry, your loan is not approved\n\n");
else
printf("Congratulation!!! Your loan is approved.\n\n");
printf("Reset <y-yes/n-no>:");
fflush(stdin);
scanf("%c",&reset);
printf("\n");
}while(reset!='n');
return 0;
}
int dec_2017_6 (void)
{
int time_in=0, time_out=0, day, total=0, hour=0;
for(day=1;day<=7;day++)
{
printf("Day %d\n",day);
printf("Time in (24 hour format): ");
scanf("%d",&time_in);
fflush(stdin);
printf("Time out (24 hour format): ");
scanf("%d",&time_out);
fflush(stdin);
hour+=time_out/100-time_in/100;
if ((time_out%100-time_in%100)>0 || (time_in%100-time_out%100)>0)
hour++;
switch(day)
{
case 1: case 2: case 3: case 4: case 5:
{
if (hour>3)
{
total+=2;
hour-=3;
total+=hour;
}
else
if (hour<=3)
total+=2;
break;
}
case 6: case 7:
{
if (hour>0)
total+=8;
}
}
}
printf("\n\nTotal parking fee per week is : RM%d.00",total);
return 0;
}