#include
<stdio.h>
int
main()
{
int
y0,
m0,
d0,
y1,
m1,
d1,
age
while
(
scanf("%d%d%d%d%d%d",
&y0,
&m0,
&d0,
&y1,
&m1,
&d1
)
){
age
=
y1
-
y0
-
1
if
(
m1
>
m0
||
m1
==
m0
&&
d1
>=
d0
)
++age
printf("年龄为:%d周岁!\n",
age)
}
return
0
}
4.
#include
<stdio.h>
#include
<memory.h>
int
main()
{
char
p[500]
int
i,
count
while
(
scanf("%s",
&p)
){
count
=
0
for
(
i
=
0
i
!=
strlen(p)
++i
)
if
(
p[i]
>=
'a'
&&
p[i]
<=
'z'
)
++count
printf("%d\n",
count)
}
return
0
}
2.
#include
<stdio.h>
int
main()
{
int
n
while
(
scanf("%d",
&n)
){
if
(
(
n
&
1
)
==
0
)
printf("%d是偶数!\n",
n)
else
printf("%d,是奇数!\n",
n)
}
return
0
}
第三题(用EFO结束)?EOF吧?EOF已经是文件尾,怎样输出结果?
按照题目要求编写的求最大值和最小值及它们的位置的C语言程序如下
#include<stdio.h>
int max(int a[],int n,int *p){
int i=0,m=a[0]
*p=i
for(i=1i<ni++){
if(m<a[i]){
m=a[i]
*p=i
}
}
return m
}
int min(int a[],int n,int *p){
int i=0,m=a[0]
*p=i
for(i=1i<ni++){
if(m>a[i]){
m=a[i]
*p=i
}
}
return m
}
int main(){
int m,n,t=0,*p=&t,a[10]={31,28,73,83,27,56,12,43,34,63}
m=max(a,10,p)
printf("最大值为%d,位置为%d\n",m,*p)
n=min(a,10,p)
printf("最小值为%d,位置为%d\n",n,*p)
return 0
}
#include <stdio.h>
int main()
{
char strw[1000], stre[1000], *s, *t
scanf("%s %s", strw, stre)
s = strw
t = stre
while (*s != '\0' &&*s == *t)
++s, ++t
if (*s <*t)
printf("-1\n")
else if (*s >*t)
printf("1\n")
else
printf("0\n")
return 0
}
如果出现诸如 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. 的编译错误或警告,可将代码 "scanf("%s %s", strw, stre)" 用 "scanf_s("%s %s", strw, 1000, stre, 1000)" 替代;
部分测试样例