7.2
#include<stdio.h>
void Count(int a,int b){
int Max;
if(a>b){
Max = a;
} else{
Max = b;
}
printf("较大的是%d",Max);
}
int main(void){
int j,k;
printf("输入两个数字:");
scanf("%d,%d",&j,&k);
Count(j,k);
}
7.3
#include<stdio.h>
int LCM(int a,int b){
int x,find = 0;
for(x = 1;!find;x++){
if(x%a==0&&x%b==0){
find = 1;
}
}
return x-1;
}
int main(){
int j,k;
printf("输入两个数字:");
scanf("%d,%d",&j,&k);
printf("%d",LCM(j,k));
return 0;
}
7.5
#include <stdio.h>
int Fact(int n){
int p = 1,i;
for(i = 1;i<=n;i++){
p*=i;
}
return p;
}
int main(void){
int a,b;
scanf("%d",&a);
for(b = 1;b<=a;b++){
printf("%d!=%d\n",b,Fact(b));
}
}
7.6
#include <stdio.h>
int Fact(int n){
int p ,i,j,sum=0;
for(j = 1;j<=n;j++) {
p = 1;
for (i = 1; i <= j; i++) {
p *= i;
}
sum+=p;
}
return sum;
}
int main(void){
int a;
scanf("%d",&a);
printf("和为%d", Fact(a));
}
7.7
#include<stdio.h>
int Gcd(int a,int b);
int main()
{
int m,n;
printf("Input m,n:");
scanf("%d,%d",&m,&n);
printf("%d\n",Gcd(m,n));
return 0;
}
int Gcd(int a,int b)
{
int t,min,find=0;
min=a<b?a:b;
t=min;
for(t=min;!find;t--)
{
a%t==0;
b%t==0;
if(a%t==0&&b%t==0)
return t;
}
find=1;
}
#include<stdio.h>
int Gcd(int a,int b);
int main()
{
int m,n;
printf("Input m,n:");
scanf("%d,%d",&m,&n);
printf("%d\n",Gcd(m,n));
return 0;
}
int Gcd(int a,int b)
{
int r,temp;
r=a%b;
if(r==0)
return b;
else
do{
temp=b;
b=r;
a=temp;
r=a%b;
}while(r!=0);
return b;
}
#include<stdio.h>
int Gcd(int a,int b);
int main()
{
int m,n;
printf("Input m,n:");
scanf("%d,%d",&m,&n);
printf("%d\n",Gcd(m,n));
return 0;
}
int Gcd(int a,int b)
{
return a == 0 ? b:Gcd(b%a,a);
}
|