• 微信公众号：美女很有趣。 工作之余，放松一下，关注即送10G+美女照片！

# 实验四

2周前 (04-29) 8次浏览

1.

```#include<stdio.h>
long long fun(int x);
int main(){
int n;
long long f;
while(scanf("%d",&n)!=EOF){
f=fun(n);
printf("n=%d,f=%11dn",n,f);
}
return 0;
}

long long fun(int x)
{
long long k;
if (x==1)
k=1;
else
k=2*fun(x-1)+1;

return k;
}```

1.

```#include <stdio.h>
long long fac(int n);  // 函数声明

int main() {
int i,n;

printf("Enter n:n ");
scanf("%d", &n);

for(i=1; i<=n; ++i)
printf("%d! = %lldn", i, fac(i));

return 0;
}

// 函数定义
long long fac(int n) {
static long long p = 1;

p = p*n;

return p;
}```

```long long fac(int n);  // 函数声明

int main() {
int i,n;

printf("Enter n:n ");
scanf("%d", &n);

for(i=1; i<=n; ++i)
printf("%d! = %lldn", i, fac(i));

return 0;
}

// 函数定义
long long fac(int n) {
static long long p = 1;
printf("p=%11dn",p);
p = p*n;

return p;
}```

2.

```#include<stdio.h>
int func(int, int);

int main() {
int k=4,m=1,p1,p2;

p1 = func(k,m) ;
p2 = func(k,m) ;
printf("%d,%dn",p1,p2) ;

return 0;
}

int func(int a,int b) {
static int m=0,i=2;

i += m+1;
m = i+a+b;

return (m);
}```

1.

```#include <stdio.h>
#include <stdlib.h>
#define N 1000
int fun(int n,int m,int bb[N]) {
int i,j,k=0,flag;

for(j=n;j<=m;j++) {
flag=1;
for(i=2;i<j;i++)
if(j%i==0) {
flag=0;
break;
}
if(flag==1)
bb[k++]=j;
}
return k;
}

int main(){
int n=0,m=0,i,k,bb[N];

scanf("%d",&n);
scanf("%d",&m);

for(i=0;i<m-n;i++)
bb[i]=0;

k=fun(n,m,bb);

for(i=0;i<k;i++)
printf("%4d",bb[i]);

return 0;
}```

2.

1.

```#include <stdio.h>
void dec2n(int x, int n);

int main() {
int x;

printf("输入一个十进制整数: ");
scanf("%d", &x);

dec2n(x, 2);
dec2n(x, 8);
dec2n(x, 16);

return 0;
}

void dec2n(int x, int n) {

int i = 0, a[32],b[32],c[32];
char t;
//转化为二进制
if(n==2){
while (x > 0) {
a[i] = x % 2;
i = i + 1;
x = x / 2;
}
for (i--; i >= 0; i--)
printf("%d", a[i]);
printf("n");
}
//转化为八进制
else if(n==8){
while (x > 0) {
b[i] = x % 8;
i = i + 1;
x = x / 8;
}
for (i--; i >= 0; i--)
printf("%d", b[i]);
printf("n");

}
//转化为十六进制
else if (n==16){
while (x > 0) {
c[i] = x % 16;
i = i + 1;
x = x / 16;
}
for (i--; i >= 0; i--){
if(c[i]>=10){
t = 'A'+c[i]-10;
printf("%c",t);
}
else
printf("%d", c[i]);
}
printf("n");

}

} ```

2.

emmmmm总的来说这次问题挺多的，包括但不限于，实验1的问题，实验2的运行截图和文件中有点出入，以及实验4课上听了之后没记太清楚，又问了好久别人加之“借鉴”才得出来的巴拉巴拉~