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;
}
- c语言用户标识符规则,c语言用户自定义标识符作用
- c语言生成随机数矩阵,随机数法生成矩阵
- c语言比较三个数大小输出最小数,三个数比大小c语言输出最大值
- c语言强制类型转换详解,c语言类型转换注意点
- 乙肝抗体30多还用打疫苗吗
- 农村俗语“六月立秋快加油,七月立秋慢悠悠”是什么意思?今年立秋是哪一天?
- 我老婆左眼一直跳,各位大神有什么好的解决方案?
- 砖茯茶是什么茶?喝它有什么讲究?
- 属鼠男是什么性格?
- 桃胶的功效与作用及食用方法是什么?
特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
