| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 11655 人关注过本帖, 13 人收藏
标题:[分享][转载]C入门必做的一些题目,有兴趣的来看
只看楼主 加入收藏
C语言学习者
Rank: 4
等 级:贵宾
威 望:13
帖 子:1278
专家分:0
注 册:2006-9-26
收藏
得分:0 

我个人建议固定一些编程序题目会好一些。


谁有强殖装甲第二部,可以Q我460054868
2006-09-30 20:54
C之Itachi
Rank: 1
等 级:新手上路
帖 子:111
专家分:0
注 册:2006-7-16
收藏
得分:0 

把这个顶起来~呵呵


2006-10-01 16:40
rbh1347
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-10-1
收藏
得分:0 
晕了
2006-10-01 20:02
xiaoyunhu
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-9-24
收藏
得分:0 
有意思,顶吧...

小晕乎
2006-10-02 18:37
yamu2000
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-9-12
收藏
得分:0 

第4题还没做出来,现做后面的吧。
第5题:
main()
{int i=0,j,NUM,N,a[16];
char note[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
clrscr();
for(j=0;j<16;j++) a[j]=0;
printf("Please input the NO.");scanf("%d",&NUM);
printf("Transform to ?");scanf("%d",&N);
while(NUM != 0)
{a[15-i]=NUM % N;
NUM=(NUM-a[15-i])/N;
i=i+1;}
printf("NUM=%dx",N);
for(i=0;i<16;i++) if(a[i]) {j=i;break;}
for(;j<16;j++) printf("%c",note[a[j]]);
getch();
}

第6题
#define NUM 9
main()
{int i,j,k=1,m,mi,mj,a[NUM][NUM],ind[4]={NUM-1,NUM-1,0,1};
clrscr();
for(i=0;i<NUM;i++)
for(j=0;j<NUM;j++)
{a[i][j]=k;k++;}
/* back*/
printf("back:\n");
for(i=NUM-1;i>=0;i--)
for(j=NUM-1;j>=0;j--)
{printf("%4d",a[i][j]);
if(j==0) printf("\n");
}
printf("\n");
/* snake */
printf("snake:\n");
k=1;
for(m=0;m<=(NUM-1)*(NUM-1);m++)
for(i=0;i<NUM;i++)
for(j=0;j<NUM;j++)
{if((i+j)==m)
{if(m%2==0)
{a[i][j]=k;k=k+1;}
else
{a[j][i]=k;k=k+1;}
}
}
for(i=0;i<NUM;i++)
for(j=0;j<NUM;j++)
{printf("%4d",a[i][j]);
if(j==NUM-1) printf("\n");}
printf("\n");

/*cycle*/
printf("cycle:\n");
k=1;i=0;j=0;
while(ind[0]>=ind[2])
{while(i<=ind[0])
{a[i][j]=k;i++;k++;}
ind[0]--;i--;j++;
while(j<=ind[1])
{a[i][j]=k;j++;k++;}
ind[1]--;j--;i--;
while(i>=ind[2])
{a[i][j]=k;i--;k++;}
ind[2]++;i++;j--;
while(j>=ind[3])
{a[i][j]=k;j--;k++;}
ind[3]++;j++;i++;}
for(i=0;i<NUM;i++)
for(j=0;j<NUM;j++)
{printf("%4d",a[i][j]);
if(j==NUM-1) printf("\n");}
printf("\n");
getch();
}

2006-10-06 10:51
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 
好啊!有时间做一做啊!

该学习了。。。
2006-11-03 14:37
zhengjcpj
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-11-3
收藏
得分:0 

有答案吗?

2006-11-03 14:57
shily
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2006-11-3
收藏
得分:0 

好难哦,我是刚开始学C语言的.


学习学习再学习.
2006-11-03 15:17
link1130
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2006-10-29
收藏
得分:0 
挣扎中

对我来说好难

2006-11-03 16:13
hao0716
Rank: 4
等 级:业余侠客
威 望:1
帖 子:353
专家分:222
注 册:2006-4-11
收藏
得分:0 

18题的,以前是做过个青蛙跳的,题目一样 大家需要的话我就贴下注释了....代码运行可以

#include <stdio.h>

#include <stdlib.h>

#define DEBUG 0
#define TRUE 1
#define FALSE 0


typedef struct _Frog
{
int spaceflag;//1 = have space, -1=no space
int direct;//1 = right, 0 = no direct, -1 = left
char* id;
int address;
}Frog;

Frog frog[7];
static void Printf(Frog* frog);
static int Act(Frog* frog);
static int Review(Frog* frog);

int main()
{
int a,i,x;
x=0;
frog[0].spaceflag=-1;
frog[0].direct=1;
frog[0].id="A1";
frog[0].address=0;

frog[1].spaceflag=1;
frog[1].direct=1;
frog[1].id="A2";
frog[1].address=1;

frog[2].spaceflag=1;
frog[2].direct=1;
frog[2].id="A3";
frog[2].address=2;

frog[3].spaceflag=-1;
frog[3].direct=0;
frog[3].id="space";
frog[3].address=3;

frog[4].spaceflag=1;
frog[4].direct=-1;
frog[4].id="B4";
frog[4].address=4;

frog[5].spaceflag=1;
frog[5].direct=-1;
frog[5].id="B5";
frog[5].address=5;

frog[6].spaceflag=-1;
frog[6].direct=-1;
frog[6].id="B6";
frog[6].address=6;

while(1)
{
Printf(frog);
a=Act(frog);
system("cls");

if(DEBUG)
{

for(a =0;a<7;a++)
{
printf("%d\n",(frog+a)->spaceflag);
}
}
x=0;
for(i=0;i<7;i++)
{
if((frog+i)->spaceflag == -1)
{
x=x+1;
}
}
if(x==7)
break;
}
;


printf("congratulations, pass\n");
}

int Act(Frog* frog)
{
int y,i;
printf("please input id:");
scanf("%d", &y);

if(y<4)
y=y-1;

if(((frog+3)->address==y)||(y>6))
{
printf("Id error,don't move\n");

}
else
{

if((frog+y)->spaceflag == 1)
{
if(((frog+y)->direct == 1)&&((frog+y)->address<(frog+3)->address))
{
if(((frog+3)->address)-((frog+y)->address) == 1)
{
(frog+y)->address = (frog+y)->address+1;
(frog+3)->address = (frog+3)->address-1;
for(i=0;i<7;i++)
{
if(i<3)
{
if((((frog+3)->address-(frog+i)->address)<=2)&&((frog+3)->address>(frog+i)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
else
{
if((((frog+i)->address-(frog+3)->address)<=2)&&((frog+i)->address>(frog+3)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
}

}
else
{
(frog+y)->address = (frog+y)->address+2;
(frog+3)->address = (frog+3)->address-2;
for(i=0;i<7;i++)
{
if(i<3)
{
if((((frog+3)->address-(frog+i)->address)<=2)&&((frog+3)->address>(frog+i)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
else
{
if((((frog+i)->address-(frog+3)->address)<=2)&&((frog+i)->address>(frog+3)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
}
}
}
else
if(((frog+y)->direct == -1)&&((frog+y)->address>(frog+3)->address))
{
if(((frog+y)->address)-((frog+3)->address) == 1)
{
(frog+y)->address = (frog+y)->address-1;
(frog+3)->address = (frog+3)->address+1;
for(i=0;i<7;i++)
{
if(i<3)
{
if((((frog+3)->address-(frog+i)->address)<=2)&&((frog+3)->address>(frog+i)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
else
{
if((((frog+i)->address-(frog+3)->address)<=2)&&((frog+i)->address>(frog+3)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
}
}
else
{
(frog+y)->address = (frog+y)->address-2;
(frog+3)->address = (frog+3)->address+2;
for(i=0;i<7;i++)
{
if(i<3)
{
if((((frog+3)->address-(frog+i)->address)<=2)&&((frog+3)->address>(frog+i)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
else
{
if((((frog+i)->address-(frog+3)->address)<=2)&&((frog+i)->address>(frog+3)->address))
(frog+i)->spaceflag = 1;
else
(frog+i)->spaceflag = -1;
}
}
}
}
else
{
printf("Id error,don't move\n");
return(1);
}
}
else
{
printf("Id error,don't move\n");
return(1);
}
}
return(0);
}


void Printf(Frog* frog)
{
int x,y;//x = address, y = id
for(x=0;x<7;x++)
{
for(y=0;y<7;y++)
{
if((frog+y)->address==x)
{
printf("%s\t", (frog+y)->id);
}
}
}
}


2006-11-03 17:45
快速回复:[分享][转载]C入门必做的一些题目,有兴趣的来看
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030212 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved