|
ASCII
码文件
(
文本文件
)a1.t
xt
中内容:
income $100,$300
,
$28.5,S76.8
#include "stdio.h"
main()
{ FILE *fp;
char ch;
int count;
if((fp=fopen(
“
a1.txt
”
,"r"))==NULL)
{
printf("Cannot open this file
\
n");
exit(0);
}
count=0;
while(! feof(fp))
{
ch=fgetc(fp);
if (ch==
’
$
’
)
count++;
}
printf("%d",count);
fclose(fp);
}
5.
请阅读以下程序:
#include
<stdio.h>
char fun(char
*s)
{if(*s<='Z'&&*s>='A')
*s+=32;
return *s;
}
main()
{ char c
[
80
]
,*p;
p=c;
scanf(
“
%s
”
,p);
for(;*p;p++)
putchar(fun(p));
printf(
“\
n
”
)
;
}
若运行时输入
Good
〈回车〉,写出运行后的输出结果。
6.
请阅读以下程序,写出下述程序运行后的输出结果
include
“
stdio.h
”
struct st
{ int num;
char name
[
10
]
;
int age;
};
main()
{ struct st s
[
3
]
={{1901,"zhang",20},{1902,"Wang",19},{1903,"Zhao",18}};
struct st *p;
p=s+2;
printf(
“
%s
\
n
”
,s
[
0
]
.name);
printf (
“
%s
\
n",p
→
name);
}
四、程序填空
(
每空
2
分,共
16
分
)
1.
下面程序的功能是输出
1
至
100
之间每位数字的乘积大于每位数字的和的数。例如
数
56(
积为
30
,和为
11)
。请在下列程序的空格处填上适当的内容。
#include <stdio.h>
main()
{ int n,k=1,s=0,m;
for(n=1;n<=100;____)
{ k=1;s=0;
____;
while(m!=0)
{ k*=m%10;
s______;
m=m/10;
}
if(k>s)printf(
“
%d",n);
}
}
2.
用
gets()
函数从键盘上输入一个字符串,若该字符串是回文,则输出
yes
,否则输
出
no
,
(
若字符串正读与反读一样,是回文。如“
abccba
”
,"aba"
是回文
)
请在下列程序的空
格处填上适当的内容。
#include "string.h"
main()
{ char s
[
81
]
,answer;
int i,j;
answer='y';
gets(s);
j=strlen(s)-1;
for(i=0;i<j;i++,______)
if(s
[
i
]
!=s
[
j
]
)
{
answer=
|