1.
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char ch;
int count_blank = 0,count_line_feed = 0,count_other = 0;
while((ch = getchar()) != '#')
{
switch(ch)
{
case ' ':count_blank++;break;
case '\n':count_line_feed++;break;
default:count_other++;break;
}
}
printf("%d spaces are there\n",count_blank);
printf("%d line break are there\n",count_line_feed);
printf("%d other are there\n",count_other);
return 0;
}
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char ch;
int count = 0;
while((ch = getchar()) != '#')
{
if(ch == '\n')
{
printf("'\\n'-%3d ",'\n');
}
else if(ch == '\t')
{
printf("'\\t'-%3d ",'\t');
}
else
{
printf("'%c'-%3d ",ch,ch);
}
if(++count % 8 == 0)
{
printf("\n");
}
}
return 0;
}
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int num;
int even = 0,odd = 0;
int sum_even = 0,sum_odd = 0;
printf("Please enter a inter(and q to quit): ");
while((scanf("%d",&num) == 1) && (num != 0))
{
if(num % 2 == 0)
{
even++;
sum_even += num;
}
else
{
odd++;
sum_odd += num;
}
printf("Please enter a inter(and q to quit): ");
}
printf("The even's number is %d\n",even);
printf("The odd's number is %d\n",odd);
if(even > 0)
printf("The even's average is %.2f\n",(float)sum_even/even);
if(odd > 0)
printf("The odd's average is %.2f\n",(float)sum_odd/odd);
return 0;
}
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char ch;
int count = 0;
while((ch = getchar()) != '#')
{
if(ch == '!')
{
putchar('!');
putchar('!');
count++;
}
else if(ch == '.')
{
putchar('!');
count++;
}
else
{
putchar(ch);
}
}
printf("Number of substitutions are %d.\n",count);
return 0;
}
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char ch;
int count = 0;
while((ch = getchar()) != '#')
{
switch (ch)
{
case '!':putchar('!');putchar('!');count++;break;
case '.':putchar('!');count++;break;
default:putchar(ch);break;
}
}
printf("Number of substitutions are %d.\n",count);
return 0;
}
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char ch,prev;
int count = 0;
while((ch = getchar()) != '#')
{
if(prev == 'e')
{
if(ch == 'i')
count++;
}
prev = ch;
}
printf("The ei's number are %d.",count);
return 0;
}
#include <stdio.h>
#include <ctype.h>
#define SALARY 10
#define OVERTIME 40
#define RATE1 0.15
#define RATE2 0.20
#define RATE3 0.25
#define THE_TOTAL_SALARY1 300
#define THE_TOTAL_SALARY2 150
int main(void)
{
int hour_per_week;
float total_wage_bil;
float taxes;
float net_inclome;
printf("Please enter the number of hours you work in a week: ");
scanf("%d",&hour_per_week);
if(hour_per_week > OVERTIME)
{
total_wage_bil = hour_per_week * SALARY * 1.5;
}
else
{
total_wage_bil = hour_per_week * SALARY;
}
if(total_wage_bil < THE_TOTAL_SALARY1)
{
taxes = total_wage_bil * RATE1;
}
else if(total_wage_bil < THE_TOTAL_SALARY1 + THE_TOTAL_SALARY2)
{
taxes = THE_TOTAL_SALARY1 * RATE1 + (total_wage_bil - THE_TOTAL_SALARY1) * RATE2;
}
else
{
taxes = THE_TOTAL_SALARY1 * RATE1 \
+ THE_TOTAL_SALARY2 * RATE2 \
+ (total_wage_bil- THE_TOTAL_SALARY1-THE_TOTAL_SALARY2)*RATE3;
}
net_inclome = total_wage_bil - taxes;
printf("The total wage bil is %.2f\n", total_wage_bil);
printf("The taxes is %.2f\n",taxes);
printf("The net inclome is %.2f\n",net_inclome);
return 0;
}
#include <stdio.h>
#include <ctype.h>
#define OVERTIME 40
#define RATE1 0.15
#define RATE2 0.20
#define RATE3 0.25
#define THE_TOTAL_SALARY1 300
#define THE_TOTAL_SALARY2 150
void show_menu(void)
{
for(int i = 0; i < 100; i++)
printf("*");
printf("\n");
printf("Enter the number corresponding to the desired pay rate or action\n");
printf("1) $8.7h/hr 2) $9.33/hr\n");
printf("3) $10.00h/hr 4) $11.20/hr\n");
printf("5) quit\n");
for(int i = 0; i < 100; i++)
printf("*");
printf("\n");
}
int main(void)
{
int hour_per_week;
float total_wage_bil;
float taxes;
float net_inclome;
int choice;
float salary;
show_menu();
while((scanf("%d",&choice) == 1) && choice != 5)
{
if(choice < 1 || choice > 5)
{
show_menu();
continue;
}
switch(choice)
{
case 1:salary = 8.75;break;
case 2:salary = 9.33;break;
case 3:salary = 10.00;break;
case 4:salary = 11.20;break;
default:break;
}
printf("Please enter the number of hours you work in a week: ");
scanf("%d",&hour_per_week);
if(hour_per_week > OVERTIME)
{
total_wage_bil = hour_per_week * salary * 1.5;
}
else
{
total_wage_bil = hour_per_week * salary;
}
if(total_wage_bil < THE_TOTAL_SALARY1)
{
taxes = total_wage_bil * RATE1;
}
else if(total_wage_bil < THE_TOTAL_SALARY1 + THE_TOTAL_SALARY2)
{
taxes = THE_TOTAL_SALARY1 * RATE1 + (total_wage_bil - THE_TOTAL_SALARY1) * RATE2;
}
else
{
taxes = THE_TOTAL_SALARY1 * RATE1 \
+ THE_TOTAL_SALARY2 * RATE2 \
+ (total_wage_bil- THE_TOTAL_SALARY1-THE_TOTAL_SALARY2)*RATE3;
}
net_inclome = total_wage_bil - taxes;
printf("The total wage bil is %.2f\n", total_wage_bil);
printf("The taxes is %.2f\n",taxes);
printf("The net inclome is %.2f\n",net_inclome);
show_menu();
}
return 0;
}
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int num;
printf("Please input a number(number > 0):");
while(scanf("%d",&num) == 1 && num > 0)
{
if(num == 1)
{
printf("1 is not primer.\n");
printf("You can input another number:");
}
for(int i = 2; i <= num; i++)
{
int t;
for(t = 2; t*t <= i;t++)
{
if(i % t == 0)
break;
}
if(t*t > i)
{
printf("%d ",i);
}
}
printf("\n");
printf("Please input a number(number > 0):");
}
return 0;
}
#include <stdio.h>
#include <ctype.h>
#define RATE1 0.15
#define RATE2 0.28
void show_menu(void)
{
printf("Please enter your options(and input 5 to quit): \n");
for(int i = 0; i < 100; i++)
printf("*");
printf("\n");
printf("1) single 2) household\n");
printf("3) married 4) divorce\n");
printf("5) quit\n");
for(int i = 0; i < 100; i++)
printf("*");
printf("\n");
}
int main(void)
{
int number;
float salary;
float rate;
float taxes_on_wages;
show_menu();
while(scanf("%d", &number) && number != 5)
{
if(number < 1 || number > 5)
{
show_menu();
continue;
}
switch(number)
{
case 1:taxes_on_wages = 17850;break;
case 2:taxes_on_wages = 23900;break;
case 3:taxes_on_wages = 29750;break;
case 4:taxes_on_wages = 14875;break;
default:break;
}
printf("Please input your salary: ");
scanf("%f",&salary);
if(salary <= taxes_on_wages)
{
rate = salary * RATE1;
}
else
{
rate = taxes_on_wages * RATE1 + (salary - taxes_on_wages)*RATE2;
}
printf("You need pay %.2f rate\n",rate);
show_menu();
}
return 0;
}
#include <stdio.h>
#include <ctype.h>
#define ONION 2.05
#define BEET 1.15
#define CARROT 1.09
#define LOWEST_DISCOUT 100
#define DISCOUNT 0.05
#define WEIGHT1 5
#define WEIGHT2 20
#define PACKAGING1 6.5
#define PACKAGING2 14
#define PACKAGING3 0.5
void show_menu(void)
{
printf("Please input (abcd) to choice your option:\n");
for(int i = 0; i < 100; i++)
printf("*");
printf("\n");
printf("a) onion: %.2f/pound b) beet: %.2f\n",ONION,BEET);
printf("c) carrot: %.2f/pound q) quit\n",CARROT);
for(int i = 0; i < 100; i++)
printf("*");
printf("\n");
}
int main(void)
{
char ch;
float weight = 0;
float sum_weight = 0;
float onion_weight = 0,beet_weight = 0,carrot_weight = 0;
float order_amount = 0;
float discount = 0;
float packaging = 0;
float finally_amount = 0;
show_menu();
while((ch = getchar()) != 'q')
{
while(getchar() != '\n')
continue;
if(ch != 'a' && ch != 'b' && ch != 'c')
{
show_menu();
continue;
}
switch(ch)
{
case 'a':printf("Please enter the weight \
of the onion you want to order:");
scanf("%f",&weight);
onion_weight += weight;
printf("You are order %.2f pound onion\n",onion_weight);
break;
case 'b':printf("Please enter the weight\
of the beet you want to order:");
scanf("%f",&weight);
beet_weight += weight;
printf("You are order %.2f pound beet\n",beet_weight);
break;
case 'c':printf("Please enter the weight\
of the carrot you want to order:");
scanf("%f",&weight);
carrot_weight += weight;
printf("You are order %.2f carrot onion\n",carrot_weight);
break;
default:break;
}
while(getchar() != '\n')
continue;
show_menu();
}
sum_weight = onion_weight + beet_weight + carrot_weight;
order_amount = ONION * onion_weight + BEET * beet_weight + CARROT * carrot_weight;
if(order_amount > LOWEST_DISCOUT)
{
discount = order_amount * DISCOUNT;
}
if(sum_weight <= WEIGHT1)
{
packaging = PACKAGING1;
}
else if(sum_weight <= WEIGHT2)
{
packaging = PACKAGING2;
}
else
{
packaging = (sum_weight - PACKAGING2)*PACKAGING3;
}
finally_amount = order_amount + packaging - discount;
printf("The ordered weight is %.2f\n",sum_weight);
printf("The cost of the ordered vegetables is %.2f\n",order_amount);
if(discount != 0)
{
printf("The discount is %.2f\n",discount);
}
printf("The packaging is %.2f\n",packaging);
printf("The finally cost is %.2f\n",finally_amount);
return 0;
}