高级语言程序设计第四次作业
这个作业属于哪个课程:https://edu.cnblogs.com/campus/fzu/2024C
学号:092300125
姓名:张天荣
6.16
#include<stdio.h>
int main(void) {
char ch[26];
int i;
char c = 'a';
for (i = 0; i < 26; i++,c++)
ch[i] = c;
for (i = 0; i < 26; i++)
printf("%c ", ch[i]);
return 0;
}
5.
#include<stdio.h>
int main(void) {
char c;
scanf("%c",&c);
int k=c-'A'+1,i,j,l,m;
for (i = 0; i < k; i++) {
j = 0;
for (l = 0; l < k - i-1; l++)
printf(" ");
for (c = 'A'; j <=i; j++)
printf("%c",c++);
for (j--; j > 0; j--)
printf("%c", c--);
printf("\n");
}
return 0;
}
7.
#include<stdio.h>
#include<string.h>
int main(void) {
char ch[20];
scanf("%s",ch);
int i = 0;
for (i = strlen(ch); i > 0;)
printf("%c",ch[--i]);
return 0;
}
8.
#include<stdio.h>
int main(void) {
double a, b;
while (scanf("%lf %lf",&a,&b) == 2)
printf("%lf",(a-b)/(a*b));
return 0;
}
9.
#include<stdio.h>
double math(double a,double b) {
return (a - b) / (a * b);
}
int main(void) {
double a, b;
while (scanf("%lf %lf",&a,&b) == 2)
printf("%lf",math(a,b));
return 0;
}
10.
#include<stdio.h>
int main(void) {
int max, min,sum;
scanf("%d %d",&min,&max);
while (max > min) {
sum = 0;
for (; min <= max; min++)
sum = sum + min * min;
printf("%d\n",sum);
scanf("%d %d", &min, &max);
}
return 0;
}
12.
#include<stdio.h>
int main(void) {
int n,i;
scanf("%d",&n);
double sum1=0.0,sum2=0.0;
while (n > 0) {
for (i = 0; i < n; i++) {
sum1 = sum1 + 1.0 / ((i + 1) * 1.0);
}
printf("%lf ",sum1);
for (i = 0; i < n; i++) {
if ((i + 1)%2==1)
sum2 = sum2 + 1.0 / ((i + 1) * 1.0);
else
sum2 = sum2 - 1.0 / ((i + 1) * 1.0);
}
printf("%lf\n", sum2);
scanf("%d",&n);
}
return 0;
}
13.
#include<stdio.h>
int main(void) {
int arr[8];
int i;
arr[0] = 2;
for (i = 1; i < 8; i++)
arr[i] = arr[i - 1] * 2;
i = 0;
do {
printf("%d ",arr[i++]);
} while (i < 8);
return 0;
}
15.
#include<stdio.h>
int main(void) {
char ch[256];
int i = 0;
do {
scanf("%c",&ch[i]);
} while (ch[i++] != '\n');
i = i - 2;
for (; i >= 0;i--) {
printf("%c",ch[i]);
}
return 0;
}
16.
#include<stdio.h>
int main(void) {
double a=100.0,b=100.0;
int i = 0;
do {
a = a + 100 * 0.1;
b = b + b * 0.05;
i++;
} while (a > b);
printf("%d", i);
return 0;
}
18.
#include<stdio.h>
int main(void) {
int n=5,i=1;
do {
n = 2 * (n - i);
printf("%d %d\n",i++,n);
} while (n <= 150);
return 0;
}
7.12
#include<stdio.h>
int main(void) {
int a=0,b=0,c=0;
char ch;
while ((ch = getchar()) != '#') {
if (ch == ' ')
a++;
else if (ch == '\n')
b++;
else
c++;
}
printf("%d %d %d",a,b,c);
}
2.
#include<stdio.h>
int main(void) {
int a=0,b=0,c=0;
int i=0;
char ch;
while ((ch = getchar()) != '#') {
if(++i%8!=0)
printf("%c-%d ",ch,ch);
else
printf("%c-%d\n", ch, ch);
}
}
4.
#include<stdio.h>
int main(void) {
int a=0,b=0,c=0;
int i=0;
char ch;
while ((ch = getchar()) != '#') {
if (ch == '!') {
printf("!!");
i++;
}
else if (ch == '.') {
printf("!");
i++;
}
else
printf("%c",ch);
}
printf("\n%d",i);
}
5.
#include<stdio.h>
int main(void) {
int a=0,b=0,c=0;
int i=0;
char ch;
while ((ch = getchar()) != '#') {
switch (ch)
{
case '!':
printf("!!");
i++;
break;
case '.':
printf("!");
i++;
break;
default:
printf("%c", ch);
}
}
printf("\n%d",i);
}
6.
#include<stdio.h>
int main(void) {
int a=0,b=0,c=0;
int i=0,check=0;
char ch;
while ((ch = getchar()) != '#') {
if (ch == 'e')
check = 1;
else if (ch == 'i') {
if (check)
i++;
check = 0;
}
else
check = 0;
}
printf("\n%d",i);
}
7.
#include<stdio.h>
int main(void) {
double n;
scanf("%lf",&n);
double a, b;
if (n <= 40)
a = 10.0 * n;
else
a = (40.0 + (n - 40.0) * 1.5) * 10.0;
if (a <= 300)
b = a * 0.15;
else if (a <= 450)
b = 300 * 0.15 + (a - 300.0) * 0.2;
else
b = 300 * 0.15 + 150 * 0.2 + (a - 450.0) * 0.25;
printf("%.2lf %.2lf %.2lf",a,b,a-b);
return 0;
}
8.
#include<stdio.h>
void Menu(void) {
printf("********************\n");
printf("1.$8.74/hr 2.9.33/hr\n");
printf("3.$10.00/hr 4.11.20/hr\n");
printf("5.Quit\n");
printf("********************\n");
}
void Math(double a,double b,double c,double n) {
if (n <= 40)
a = c * n;
else
a = (40.0 + (n - 40.0) * 1.5) * c;
if (a <= 300)
b = a * 0.15;
else if (a <= 450)
b = 300 * 0.15 + (a - 300.0) * 0.2;
else
b = 300 * 0.15 + 150 * 0.2 + (a - 450.0) * 0.25;
printf("%.2lf %.2lf %.2lf\n", a, b, a - b);
}
int main(void) {
double n;
scanf("%lf",&n);
double a, b, c;
a = b = 0.0;
int choice;
do {
Menu();
scanf("%d",&choice);
switch (choice) {
case 1:
c = 8.75;
Math(a, b, c, n);
break;
case 2:
c = 9.33;
Math(a, b, c, n);
break;
case 3:
c = 10.00;
Math(a, b, c, n);
break;
case 4:
c = 11.20;
Math(a, b, c, n);
break;
case 5:
c = 8.75;
break;
default:
printf("Try again!\n");
getch();
}
} while (choice!=5);
return 0;
}
9.
#include<stdio.h>
int main(void) {
int n,i,j,check=1;
scanf("%d",&n);
for (i = n; i > 1; i--) {
check = 1;
for (j = 2; j <= i / 2; j++) {
if (i % j == 0) {
check = 0;
break;
}
}
if (check)
printf("%d ", i);
}
return 0;
}
10.
#include<stdio.h>
void Menu(void) {
printf("**************************\n");
printf("1.单身 2.户主\n");
printf("3.已婚,共有 4.已婚,离异\n");
printf("5.Quit\n");
printf("**************************\n");
}
void Math(double n, double a) {
double tax = 0.0;
if (n <= a)
tax = n * 0.15;
else
tax = a * 0.15 + (n - a) * 0.28;
printf("%.2lf\n", tax);
}
int main(void) {
int choice;
double n;
do {
Menu();
scanf("%d",&choice);
switch(choice){
case 1:
scanf("%lf",&n);
Math(n, 17850.0);
break;
case 2:
scanf("%lf", &n);
Math(n, 23900.0);
break;
case 3:
scanf("%lf", &n);
Math(n, 29750);
break;
case 4:
scanf("%lf", &n);
Math(n, 14875);
break;
case 5:
break;
default:
printf("Try again!\n");
getch();
}
} while (choice != 5);
}
11.
#include<stdio.h>
void Menu(void) {
printf("**************************\n");
printf("a.洋蓟 b.甜菜\n");
printf("c.胡萝卜 q.退出订购\n");
printf("**************************\n");
}
void Math(double a, double b,double c) {
double m1, m2=0.0, m3;
double sum = a + b + c;
m1 = a * 2.05 + b * 1.15 + c * 1.09;
if (m1 >= 100.0)
m2 = m1 * 0.05;
if (sum <= 5)
m3 = 6.5;
else if (sum <= 20)
m3 = 14.0;
else
m3 = 14.0 + (sum - 20.0) * 0.5;
printf("%.2lf %.2lf %.2lf", m1, m2, m3);
}
int main(void) {
char choice;
double n;
double a, b, c;
a = b = c = 0.0;
do {
Menu();
scanf("%c",&choice);
switch(choice){
case 'a':
scanf("%lf",&n);
getchar();
a = a + n;
break;
case 'b':
scanf("%lf", &n);
getchar();
b = b + n;
break;
case 'c':
scanf("%lf", &n);
getchar();
c = c + n;
break;
case 'q':
break;
default:
printf("Try again!\n");
getchar();
break;
}
} while (choice != 'q');
Math(a,b,c);
return 0;
}