关于使用循环的系列打印的问题 [英] Question regarding series printing using loop

查看:73
本文介绍了关于使用循环的系列打印的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!首先,感谢所有回复我之前问题的人。另外,我想对所有回答粗鲁评论的人说我没有尖叫,实际上我并不知道资本中的文字意味着尖叫。 br $>
问候

其实我想打印系列如

aa

ab

ac

...

我现在可以使用for循环打印到前两个字母组合的结尾。

有什么方法可以使用for循环继续使用三种组合。



先谢谢,并对我之前的粗鲁回复表示抱歉。



我尝试过:



 #include< iostream>使用namespace std 

;

int main()
{

char a ='a';
string b [26];
string c [7500];
int e;
int i;
int f = 0;
for(i = 0; i< = 25; i ++)
{
b [i] = a ++;
}
while(1)
{

for(int e = 0; e< = 26; e ++)
{
c [ e] = b [f] + b [e];
cout<< c [e]<< endl;
if(e == 26)
{
f ++;
}
}
if(f == 26)
{
break;
}
}
getchar();
返回0;


}

解决方案

当您使用该语言时,为什么使用数字?字母相同:

  for  char  c1 = '  a'; c1< =  '  z'; ++ c1)
{
cout<< c1<< ENDL;
}



因此要打印多个字符组合,您只需要在第一个字符组合中添加新的循环,因此:

< pre lang =c ++> for char c1 = ' a'; c1< = ' z'; ++ c1)
{
for char c2 = ' a'; c2< = ' z'; ++ c2)
{
for char c3 = ' a'; c3< = ' z'; ++ c3)
{
cout << c1<< c2<< c3<< ENDL;
}
}
}


Hi! First of all thank you to all who replied to my earlier question.Moreover I want to say sorry to everyone whom i replied with rude comments that "I was not screaming" , actually I did not Know that words in capital means to scream.
Ques
Actually I wanted to print series like
aa
ab
ac
...
I am now able to print till end of combinations of first two letters using for loop.
Is there any way to move on to three combinations using for loop.

Thanks in advance and sorry for my previous rude replies.

What I have tried:

#include<iostream>

using namespace std;

int main()
{
	
	char a = 'a';
	string b[26];
	string c[7500];
	int e;
	int i;
	int f = 0;
	for(i=0;i<=25;i++)
	{
		b[i] = a++;
	}
while(1)
{
		 	 	
 for(int e=0;e<=26;e++)
	 {
	 	c[e] = b[f]+b[e];
	 	cout<<c[e]<<endl;
	     	if(e==26)
	     	{
	     		f++;
			 }
	 }
      if(f==26)
      {
      	break;
	  }
}
		getchar();
		return 0;
	
	
}

解决方案

Why are you using numbers, when the language allows you to use letters just the same:

for (char c1 = 'a'; c1 <= 'z'; ++c1)
{
    cout << c1 << endl;
}


So to print multiple character combinations, you just need to add new loops inside the first one, thus:

for (char c1 = 'a'; c1 <= 'z'; ++c1)
{
    for (char c2 = 'a'; c2 <= 'z'; ++c2)
    {
        for (char c3 = 'a'; c3 <= 'z'; ++c3)
        {
            cout << c1 << c2 << c3 << endl;
        }
    }
}


这篇关于关于使用循环的系列打印的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆