Professional Documents
Culture Documents
#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;
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
scanf("%d",&y);
int t = x ;
x=y;
y=t;
getchar();
return 0;
Exercise 5:
#include<stdio.h>
#include<ctype.h>
int main()
{ char ch;
int nvowels = 0 ;
do {
ch = getchar();
ch = toupper(ch);
switch(ch){
case'A':
case'E':
case'I':
case'O':
case'U': nvowels ++ ;
break;
default: consonats ++ ;
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;
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++)