1.
给出下述程序的执行结果 1, -2
#include <stdio.h>
main()
{
int x=2,y=1;
while(x--!=-1)
{
do{
y*=x;
y++;
}while(x--);
}
printf("%d, %d\n",y,x);
}
2.
下面程序的运行结果是 computerlanguage .
#include <stdio.h>
char *strc(char *str1, char *str2);
main()
{
char s1[80] = "computer", s2[] = "language", *pt;
pt = strc(s1, s2);
printf("%s\n", pt);
}
char *strc(char *str1, char *str2)
{
char *p;
for (p = str1; *p != ’\0’; p++);
do {
*p++ = *str2++;
} while(*str2 != ’\0’);
*p = ’\0’;
return (str1);
}
3.
写出程序的运行结果 1, 2, 3, 3, 5, 4
#include <stdio.h>
main()
{
int a[] = {1,2,3,4,5,6};
int *p;
p=a;
printf("%d, ",*p);
printf("%d, ",*(++p));
printf("%d, ",*++p);
printf("%d, ",*(p--));
p+=3;
printf("%d, %d\n",*p, *(a+3));
}
4.
*pp1=14,*pp2=10 a=14,b=10
#include <stdio.h>
swap(int *p1, int *p2) {
int n;
n=*p1;
*p1=*p2;
*p2=n;
}
main() {
int a=10,b=14,*pp1,*pp2;
pp1=&a;pp2=&b;
swap(pp1,pp2);
printf("*pp1=%d,*pp2=%d\n",*pp1,*pp2);
printf("a=%d,b=%d\n",a,b);
}
5.
下面的程序实现从10个数中找成最大值和最小值 p q<10 max<=*q min>*q
int max, min;
find_max_min( int *p, int n )
{
int *q;
max = min = *p;
for(q=________;______;q++)
{
if(_____)
max = *q;
else
if(____)
min=*q;
}
}
main()
{
int i, num[10];
printf("intput 10 numbers:\n");
for(i=0;i<10;i++)
scanf("%d",%num[i]);
find_max_min(num,10);
printf("max=%d;min=%d\n",max, min);
}