1/11

# 二级c语言程序设计习题及解答ch5-7函数.doc

Ch5 -6 循环结构&字符数组

#include <stdio.h>
main()
{
char ch; int i;
for(i=0;i<26;i++)
{
ch=i+65;
if(i%2==0)
printf("\n");
printf("c=%c,ASCII=%d\t",ch,ch);
}
}

Ch7 函数
#include<stdio.h>
main()
{
double m,n,z;
printf("请输入两个实数:\n");
scanf("%lf %lf",&m,&n);
printf("%lf\n",z);
}

double add(double a, double b )
{
double s;
s=a+b;
return s;

#include <stdio.h>
void try(int,int,int);
main()
{
int x=2,y=3,z=0;
printf("(1)x=%d y=%d z=%d\n",x,y,z);
try(x,y,z);
printf("(4)x=%d y=%d z=%d\n",x,y,z);
}

void try(int x,int y,int z)
{
printf("(2) x=%d y=%d z=%d\n",x,y,z);
z=x+y;
x=x*x;
y=y*y;
printf("(3) x=%d y=%d z=%d\n",x,y,z);
}

(1)    x=2 y=3 z=0
(2)    x=2 y=3 z=0
(3)    x=4 y=9 z=5
(4)    x=2 y=3 z=0

#include <stdio.h>
void swap(int ,int);
main()
{
int x=10,y=20;
printf("(1)x=%d y=%d\n",x,y);
swap(x,y);
printf("(4)x=%d y=%d\n",x,y);

}
void swap (int a,int b )
{
int t;
printf("(2)a=%d b=%d\n",a,b);
t=a;a=b;b=t;
printf("(3)a=%d b=%d\n",a,b);
}
步伐运行结果

7.6步伐应用举例

#include <stdio.h>
int isprime(int);
main()
{
int x;
printf("enter a integer number:");
scanf("%d",&x);
if(isprime(x))
printf("%d is prime \n",x);
else
printf("%d is not prime\n",x);
}
int isprime(int a)
{
int i;
for(i=2;i<=a/2;i++)
if(a%i==0)
return 0;
return 1;
}

#include <stdio.h>
#include<ctype.h>
char myupper(char ch)

{
if(ch>='a'&&ch<='z')
ch=ch-32;
return ch;
}
main()
{
char c;
while((c=getchar())!='@')
{
c=myupper(c);
putchar(c);
}
printf("\n");

}

#include<stdio.h>
long

• 页数11
• 收藏数0 收藏
• 顶次数0
• 上传人892629196
• 文件大小73 KB
• 时间2020-11-10