#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()//第六题do语句写法
{
int b, c, d;
scanf("%d", &b);
c = 0, d = 0;
do{
c = c + 2;
d = c * c;
if (d >b)
break;
printf("%d\n", d);
} while (d <= b);
return 0;
}
int main()//第六题while 语句写法
{
int b, c, d;
scanf("%d", &b);
c = 0, d = 0;
while (d < b){
c = c + 2;
d = c * c;
printf("%d\n", d);
}
return 0;
}
int main()//第七题
{
int i, n, odd, square;
printf("This program prints a table of square.\n");
printf("Enter number of entries in table: ");
scanf("%d", &n);
square = 1;
odd = 3;
for (i = 1;i<=n;i+=1) {
printf("%10d%10d\n", i, square);
square += odd;
odd += 2;
}
return 0;
}
int main()//第九题
{
float loan, rate, payment, a, b, c;
int n;
printf("Enter amount of loan: ");
scanf("%f", &loan);
printf("Enter interest rate: ");
scanf("%f", &rate);
printf("Enter monthly payment: ");
scanf("%f", &payment);
printf("Enter the number of payment: ");
scanf("%f", & a);
b = loan * (rate / 100 / 12 + 1) - payment;
for (n = 1;n <= a;n+=1) {
c = b;
printf("Balance remaining after %d payment; %0.2f\n", n, b);
b = c * (rate / 100 / 12 + 1) - payment;
}
return 0;
}
int main()//第十题
{
int dd, mm, yy, earl_d, earl_m, earl_y, earliest_d, earliest_m, earliest_y;
printf("Enter a date (mm/dd/yy): ");
scanf("%d/%d/%d", &dd, &mm, &yy);
earliest_d = dd;
earliest_m = mm;
earliest_y = yy;
do {
printf("Enter a date (mm/dd/yy): ");
scanf("%d/%d/%d", &earl_m, &earl_d, &earl_y);
if (earl_d == 0 && earl_m == 0 && earl_y == 0)
break;
if (earliest_y > earl_y)
earliest_m = earl_m, earliest_d = earl_d, earliest_y = earl_y;
else
earliest_m = mm, earliest_d = earl_d, earliest_y = earl_y;
if(earliest_m >earl_m && earliest_y ==earl_y)
earliest_m = earl_m, earliest_d = earl_d, earliest_y = earl_y;
if (earliest_m < earl_m && earliest_y == earl_y)
earliest_m = mm, earliest_d = earl_d, earliest_y = earl_y;
if (earliest_d > earl_d && earliest_m == earl_m && earliest_y == earl_y)
earliest_m = earl_m, earliest_d = earl_d, earliest_y = earl_y;
if (earliest_d < earl_d && earliest_m == earl_m && earliest_y == earl_y)
earliest_m = mm, earliest_d = earl_d, earliest_y = earl_y;
} while (1);
printf("%d/%d/%d is the earliest date", earliest_m, earliest_d, earliest_y);
return 0;
}
int main()//第十一题
{
int i, n;
float sum = 1, a = 1;
printf("Enter a number: ");
scanf("%d", &n);
for (i = 1;i <= n;i++) {
a = a * i;
sum = sum + 1/a;
}
printf("sum: %.4f", sum);
return 0;
}
int main()//第十二题
{
int i=1;
float sum = 1, a = 1,x;
printf("Enter a number: ");
scanf("%f", &x);
for (;;) {
a = a * i;
sum = sum + 1/a;
i++;
if (sum >= x)
break;
}
printf("n: %d", i);
return 0;
}
C语言现代方法:第六章课后编程操作练习(6,7,9-12题解答思路)
最新推荐文章于 2024-07-11 23:55:49 发布