一道简单的C语言试题

yuepengfei 2007-12-07 11:38:18
有字母A、B、C、D请编写程序输出由该4个字母组成的字符串,要求:
(1) 包含其中任意三个字母,
(2) 不允许重复
(3) 输出满足(1),(2),的全部字符串
...全文
152 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
laiwusheng 2007-12-08
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <conio.h>
int fun(int choice[],int r,int n)
{
int i,j;
for(i=r-1;i>=0;i--)
if(choice[i]<n-r+i)
break;
if(i<0)
return 0;
choice[i]+=1;
for(j=i+1;j<r;j++)
choice[j]=choice[j-1]+1;
return 1;
}

void comb(char source[],int total,int count)
{
int choice[5];
int i;
for(i=0;i<count;i++)
choice[i]=i;
do
{
printf("\n");
for(i=0;i<count;i++)
{
int t=choice[i];
printf("%c ",source[t]);
}
}while(fun(choice,count,total));
}

int main()
{
char array[4]={'a','b','c','d'};
clrscr();
comb(array,4,3);
getch();
return 0;
}

a b c
a b d
a c d
b c d
babaoqi 2007-12-08
  • 打赏
  • 举报
回复
#include <stdio.h>

void Print(char array[])
{
int i,j,k;
i = 0;
while(i<4)
{
j = i + 1;
while(j<4)
{
k = j +1;
while(k<4)
{
printf("%c %c %c\n",array[i],array[j],array[k]);
k++;
}
j++;
}
i++;
}
};
void main(void)
{
char array[4]={'a','b','c','d'};

Print(array);

return;
}

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧