每隔n次定制符号
cout-ing symbol after every n times?
我想将符号"."与结果组合起来,并在每8个(字符或数字)后添加一个我试着使用for循环,但我做不到,这是我的代码,它是一种求和,从较大的数字中减去较小的数字,然后在第一个过程中得到较大数字的符号"a",然后从较大数字中减去更小的数字,直到结束。我想要的是在"A"之前和每8个过程之后定制".":
#include<iostream>
using namespace std;
int main()
{
int A=26;
int B=7;
cout<<endl;
while(A!=B)
{
if(A>B)
{
A=A-B;
if(A==B){cout<<"AB";}
else cout<<"A";
}
else
{
B=B-A;
if(A==B){cout<<"BA";}
else cout<<"B";
}
}
cout<<endl;
getchar();
return 0;
}
保留一个int count
变量。在每个过程中递增++count
,当count
变为8时,打印您想要的任何内容。
类似这样的东西:
int main()
{
int A=26;
int B=7;
char bigger='.'; //I suppose this is what you want to print periodically!
int count = 0;
cout << bigger;
while(A!=B)
{
if(A>B)
{
A=A-B;
if(A==B) { cout << "AB"; count += 2;}
else { cout << "A"; ++count; }
}
else
{
B=B-A;
if(A==B) { cout << "BA"; count += 2; }
else { cout << "B"; ++count; }
}
if(count == 8)
{
cout << bigger;
count = 0; //reset it back to 0
}
}
cout<<endl;
getchar();
return 0;
}
相关文章:
- 为什么这个do-while循环每隔一个循环只写入数组?
- android.hardware.Camera 无法每隔 2 次打开一次
- 每隔几秒钟移动一次对象
- 循环每隔一行跳过一次
- 删除链表的每隔一个节点
- 具有两个变量的"for"循环,一个变量每次迭代递增,每隔一次迭代递增
- 我的函数返回的是打印到控制台,它只会在我调用它时每隔一段时间C++
- 在读取 Visual C++ 中的二进制文件(而不是其他编译器)后,每隔一个字符都是 NULL
- 每隔n次反转一个字符串
- 如何从字符串中每隔16个字节复制一次数据
- 每隔一行或每一列提取一个特征矩阵作为一个新矩阵
- 每隔n个字符打印一行换行符
- 为什么用于解析我读取的行的内部循环每隔一次迭代就会通过外部读取循环跳过
- C++.从文本文件读取.每隔一段就缺失一次
- JNI_CreateJavaVM() 每隔一次运行应用程序时都会失败(确切地说)
- 每隔几毫秒写入一个文件的最有效(最快)方法是什么
- 在opencv:C++中每隔3秒绘制并显示一个矩形
- Qt每隔一秒创建一个新线程
- 从文件中读取和存储数据时,每隔一行数据就会被跳过
- 每隔n次定制符号