1. C語言簡單編程題,由提示編寫程序,謝謝大神的幫助!!十分感激!!
#include <stdio.h>
int max(int a[], int n) {
int i = 0,m;
m = a[0];
for(i = 1;i < n;i++)
if(a[i] > m) m = a[i];
return m;
}
void show(int a[],int n) {
int i;
for(i = 0; i < n; ++i)
printf("%d ",a[i]);
printf(" ");
}
int main() {
int a[] = {21,23,10,65,8,7,90,11,49,60,33,54,22,91,39,87,66,58,39,80};
int n = sizeof(a)/sizeof(a[0]);
printf("數組為: ");
show(a,n);
printf("最大元素為:%d ",max(a,n));
return 0;
}
2. 求幾道簡單C語言編程題答案
1.
#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已經是文件尾,怎樣輸出結果?