You are on page 1of 6

Exercise 1:

#include <stdio.h>
int main()
{ double num1, num2;
char op;
double result;
printf ( "Enter an expression (+ - * /): ");
scanf("%lf%c%lf",&num1 , &op, &num2);
switch (op)
{ case'+':result=num1 + num2;
printf ("result:%lf\n",result);
break;
case'-':result=num1 - num2;
printf ("result:%lf\n",result);
break;
case'*':result=num1 * num2;
printf ("result:%lf\n",result);
break;
case'/':if(num2==0)
printf ("Divide by 0\n");
else
{ result=num1/num2;
printf ("result:%lf\n",result);
}
break;
default: printf("Op is not supported");
break;
}
getchar();
getchar();
return 0;
}
Exercise 2:
#include <stdio.h>
int main()
{ float pa = 9000000;
float pd = 3600000;
float income , tf , ti;
int n;
printf(" Your income of this year:");
scanf("%f",&income);
printf("Number of dependent:");
scanf("%d",&n);
tf = 12*(pa + n*pd);
printf(" Tax-free income:%f\n",tf);
ti= income - tf;
if(ti<=0)
{ printf("Taxable income = 0\n");
printf("Income tax = 0\n");}
else if (ti>0 && ti<= 5000000)
{ printf("Taxable income = %f\n",ti);
printf("Income tax = %f\n",ti*5/100);}
else if (ti>5000000 && ti<=10000000)
{ printf("Taxable income = %f\n ",ti);
printf("Income tax = %f\n",5000000*5/100 + (ti-5000000)*10/100);}
else if (ti>10000000 && ti<=18000000){
printf(" Taxable income = %f\n",ti);
printf("Income tax = %f\n",5000000*5/100+8000000*10/100+(ti-10000000)*15/100);}
else {
printf("Taxable income = %f\n",ti);
printf("Income tax = %f\n",5000000*5/100+5000000*10/100+8000000*15/100+(ti-
18000000)*20/100);}
getchar();getchar();
return 0 ;
}

Exercise 3:
#include<stdio.h>

int main()

{ int x , sum ;

sum = 0;

printf("Enter value list:");

do

{ scanf("%d",&x);

if (x!=0)

sum= sum + x ;

} while (x!=0);

printf("Total:%d",sum);

getchar();getchar;

return 0 ;

Exercise 4:
#include<stdio.h>

int main()

{ int x , y , t ;

do

{ printf(" Enter value x :");


scanf("%d",&x);

printf(" Enter value y :");

scanf("%d",&y);

int t = x ;

x=y;

y=t;

printf("Swap value: x= %d , y= %d\n",x , y);

} while(x!=0 && y!= 0);

getchar();

return 0;

Exercise 5:
#include<stdio.h>

#include<ctype.h>

int main()

{ char ch;

int nvowels = 0 ;

int consonats =0;

int nothers =0;

printf(" Nhap ch:");

do {

ch = getchar();

ch = toupper(ch);

if ((ch>'A') && (ch<'Z')){

switch(ch){

case'A':

case'E':

case'I':

case'O':

case'U': nvowels ++ ;

break;
default: consonats ++ ;

} else nothers = nothers ++;

while ( ch != '\n');

printf("Nguyen am :%d\n",nvowels);

printf("Phu am :%d\n",consonats);

printf("Con lai:%d\n",nothers);

getchar();

return 0;

Exercise 6:
#include<stdio.h>

int main()

{int code;

for(code=0; code<256; code++)

{ printf("%c : %3d, %3o, %3X\n", code, code, code, code);

if (code !=0 && code %20==0)

getchar(); }

return 0;

}
Exercise 7:
#include<stdio.h>

int main()

{ char c1 , c2;

int d;

char t;

char c;

printf("Enter c1:");

scanf("%c",&c1);

fflush(stdin);
printf("Enter c2:");

scanf("%c",&c2);

if (c1>c2)

{ t= c1 ; c1 =c2 ; c2 =t ;

d= c2 - c1 ;

printf(" d = %d\n",d);

for(c=c1;c<=c2;c++)

{ printf("%c : %6d%6o%6X\n", c, c, c, c);

You might also like