1,
#include <stdio.h>
int main(void)
{
/*
* 不知道 75 只 按50 % 增长后是多少只
* 不过答案是正确的,6 年.
*/
float a = 50;
int i = 0;
while (a <= 500) {
a *= 1.5;
i++;
}
printf("%d year\n", i);
return 0;
}
2,
#include <stdio.h>
int main(void)
{
int a[10] = {20, 10, 11, 53, 21, 2, 9, 104, 33, 24};
int i, sum = 0;
for (i = 0; i < 10; i++) {
if (a[i] % 2 == 0)
sum += a[i];
}
printf("sum=%d\n", sum);
return 0;
}
3,
#include <stdio.h>
int main(void)
{
int a[10] = {20, 10, 11, 53, 21, 2, 9, 104, 33, 24};
int i, sum = 0;
int min, max;
min = max = a[0];
for (i = 0; i < 10; i++) {
sum += a[i];
if (a[i] < min)
min = a[i];
if (a[i] > max)
max = a[i];
}
printf("min=%d, max=%d, sum=%d\n", min, max, sum);
return 0;
}
4,
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char buf[128];
int i, cn, sum = 0;
FILE *fp;
fp = fopen("test.txt", "r");
if (NULL == fp) {
printf("open err!\n");
return -1;
}
while (cn = fread(buf, 1, 128, fp)) {
for (i = 0; i < cn; i++) {
if (buf[i] >= 'a' && buf[i] <= 'z'
|| buf[i] >= 'A' && buf[i] <= 'Z')
sum++;
}
}
printf("sum=%d\n", sum);
fclose(fp);
return 0;
}
5,
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char buf[128];
int i, cn, sum = 0;
FILE *fp1, *fp2;
fp1 = fopen("test.txt", "r");
if (NULL == fp1) {
printf("open err!\n");
return -1;
}
fp2 = fopen("hello.txt", "a");
if (NULL == fp2) {
printf("open err!\n");
return -1;
}
while (cn = fread(buf, 1, 128, fp1))
fwrite(buf, 1, cn, fp2);
fclose(fp1);
fclose(fp2);
return 0;
}
温馨提示:内容为网友见解,仅供参考