C语言问题(英文)
发布网友
发布时间:2022-04-23 03:51
我来回答
共3个回答
热心网友
时间:2023-07-02 06:59
第一题:
//---------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
void pr(int x,char d[100][6])
{
int i;
for (i = 0; i<100; i++) {
if ((i+1)%x==0) {
strcpy(d[i],strcmp(d[i],"close")?"close":"open");
}
}
}
void init(int x,char d[100][6])
{
while (x>=0)
strcpy(d[x--],"close");
}
int main(void)
{
int i;
char door[100][6];
init(99,door);
for (i = 0; i<100; i++) {
pr(i+1,door);
}
for (i = 0; i<100; i++) {
printf("door %3d:\t%s\n",i+1,door[i]);
}
return 0;
}
//---------------------------------------------------------------------------
第二题:
//---------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#define SD "%d"
typedef int DT;
typedef struct el{
DT data;
struct el *next;
}elem;
typedef struct hd{
int cnt;
elem *top;
}stack;
void init(stack *stk)
{
stk->cnt=0;
stk->top=NULL;
}
void push(DT d,stack *stk)
{
elem *p;
p=malloc(sizeof(elem));
p->data=d;
p->next=stk->top;
stk->top=p;
stk->cnt++;
}
DT pop(stack *stk)
{
DT d;
elem *p;
d=stk->top->data;
p=stk->top;
stk->top=stk->top->next;
stk->cnt--;
free(p);
return d;
}
int main(void)
{
int ml=0;
stack st;
DT d;
char c;
init(&st);
do
{
c=getchar();
switch(c)
{
case '1':
scanf(SD,&d);
getchar();
push(d,&st);
ml=ml<st.cnt?st.cnt:ml;
break;
case '2':
if (st.cnt==0) {
puts("ERROR");
break;
}
d=pop(&st);
printf(SD,d);
putchar('\t');
getchar();
break;
case '3':
break;
default:puts("ERROR");break;
}
}while (c!='3');
printf("\nMaximum stack size=%d\n",ml);
return 0;
}
//---------------------------------------------------------------------------
第三题:
//---------------------------------------------------------------------------
#include <stdio.h>
#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define MAX(X,Y) ((X)>(Y)?(X):(Y))
int main(int argc, char* argv[])
{
int i,j,k;
double x[10]={0},y[10]={0},z[19]={0},tx,ty;
FILE *fp;
fp=fopen("t.txt","r");
while (!feof(fp)) {
fscanf(fp,"%d %lf %lf",&i,&tx,&ty);
x[i]=tx;
y[i]=ty;
}
fclose(fp);
for (j=0; j<19; j++) {
for (i = 0; i < MIN(j,9); i++) {
k=MAX(j-9,0);
z[j]+=x[k]*y[j-k];
}
}
for (i = 0; i<19; i++) {
printf("%g\n",z[i]);
}
return 0;
}
//---------------------------------------------------------------------------
参考资料:solaris+gcc测试正常
热心网友
时间:2023-07-02 07:00
第一题:
打印出结果如下:
1 | open
2 | close
3 | close
.
.
100 | open
===========================
#include<stdio.h>
#include<string.h>
int process(int m)
{ int n,i,j=0;
n=m;
if(n==1)return 1;
for(i=1;i<=n/2;i++)
if(n%i==0)j++;
if((j+1)&1)return 1;
else return 0;
}
int main()
{
int process(int);
char door[101][6];
int i,j=1,k;
for(i=1,k=0;i<=100;i++,k++)
process(i)?strcpy(door[k],"open"):strcpy(door[k],"close");
printf("Door NO | Status\n");
for(i=0;i<100;i++)
printf(" %d | %s\n",j++,door[i]);
return 0;
}
=============================
先一个。检验下过关不?
热心网友
时间:2023-07-02 07:00
..肯定无毒 !
哈哈哈~你不说,我还有点想法,你这么说。。。哈哈~~~