c语言用什么软件编辑,查找c语言答案的软件( 三 )


ncount++;
}
}
big++;
/*
printf("n=%d ",n);
printf("big=%d small=%d middle=%d ",big,small,middle);
printf("\");*/
}
end=clock();
printf("The num of method1 is: %d\",ncount);
printf("and the time is: %5.1f time\",difftime(end,start));
}
二、
#include <time.h>
#include <conio.h>
#include <dos.h>
main()
{
clock_t start,end; /* time_t start,end;*/
int i,big,middle,small,ncount,n;
clrscr();
start=clock(); /* start = time();*/
big=0; middle=0; small=0,i=0,n=0;
ncount=0;
printf("This a while program\");
do
{
for(small=0;small<=100;small=small+2)
for(middle=0;middle<=100;middle++)
{
n=big*3+middle*2+small/2;
i=big+middle+small;
if (n==100 && i==100)
{
printf("Big=%d,Middle=%d,Small=%d,n=%d,i=%d\",big,middle,small,n,i);
ncount++;
}
}
big++;
/*
printf("n=%d ",n);
printf("big=%d small=%d middle=%d ",big,small,middle);
printf("\");*/
}
while(big<=34);
end=clock();
printf("The num of method1 is: %d\",ncount);
printf("and the time is: %5.1f time\",difftime(end,start));
}
三、
#include <time.h>
#include <conio.h>
#include <dos.h>
main()
{
clock_t start,end; /* time_t start,end;*/
int i,big,middle,small,ncount,n;
clrscr();
start=clock(); /* start = time();*/
big=0; middle=0; small=0,i=0,n=0;
ncount=0;
printf("This a while program\");
for(big=0;big<=34;big++)
{
for(small=0;small<=100;small=small+2)
for(middle=0;middle<=100;middle++)
{
n=big*3+middle*2+small/2;
i=big+middle+small;
if (n==100 && i==100)
{
printf("Big=%d,Middle=%d,Small=%d,n=%d,i=%d\",big,middle,small,n,i);
ncount++;
}
}
/*
printf("n=%d ",n);
printf("big=%d small=%d middle=%d ",big,small,middle);
printf("\");*/
}
end=clock();
printf("The num of method1 is: %d\",ncount);
printf("and the time is: %5.1f time\",difftime(end,start));
}
实验五 函数
一、 目的要求
1. 掌握函数的定义和调用方法;
2. 掌握函数实参与行参的对应关系的 , 以及“值传递”的方式;
3. 掌握求最大公约数和最小公倍数的方法;
4. 按实验内容要求完成全程程序设计后才允许上机 。
二、 实验内容与步骤
1. 设计一个函数f , 求二个数的最大公约数int f(int x,int y);
2. 设计一个函数g , 求二个数的最小公倍数int g(int x,int y);
3. 从键盘输入三个浮点数 , 求三个数中最大数和最小数的差值 。
三、 函数的定义要求
在main( )中实现下列操作
1. a=inNumber( );
2. b= inNumber( );
3. c=f(a,b);
4. d=g(a,b);
5. 输出a , b , c , d 。
解答:
一、
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c,d;
clrscr();
a=inNumber();
b=inNumber();
c=f(a,b);
d=g(a,b);
printf("a=%d,b=%d,c=%d,d=%d\",a,b,c,d);
}
int f(int x,int y)
{
int i,t,a;
float p1,p2;
if (x>=y)
t=y;
else
t=x;
for (i=1;i<=t;i++)
{
p1=x%i;
p2=y%i;
if (p1==0 && p2==0)
{
a=i;
}
}
return a;
}


特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。