How to print flag using nested for loop?

closed account (EhA4jE8b)
I want to print a tricolor flag on the console screen using a nested for loop in c++.
But whenever I try to do so, i end up getting a straight line or a vertical ine.
Please help.
Last edited on
I assume you mean the French flag, the 'drapeau tricolore':
1
2
3
4
5
6
7
8
#include "stdio.h"
int main(){
	char const *setbluebg="\033[44m",
		*setwhitebg="\033[47m",
		*setredbg="\033[41m",
		*setstop="\033[m";
	for(int i=0;i<2;i++)printf("%s  %s  %s  %s\n",setbluebg,setwhitebg,setredbg,setstop);
}
Last edited on
closed account (EhA4jE8b)
I tried displaying the seven colors in order using the following code but it displays all the colours in a linear manner.
What's wrong with my code?


#include<conio.h>
#include<iostream.h>
void main()
{clrscr();
for(int i=1;i<256;i++)
{textcolor(2);
cout<<"\n";
for(int j=1;j<=12;j++)
{cprintf("Û"); }}

for(int a=1;a<256;a++)
{textcolor(3);
cout<<"\n";
for(int b=1;b<=12;b++)
{cprintf("Û"); }}

for(int s=1;s<256;s++)
{textcolor(4);
cout<<"\n";
for(int d=1;d<=12;d++)
{cprintf("Û"); }}

for(int f=1;f<256;f++)
{textcolor(5);
cout<<"\n";
for(int g=1;g<=12;g++)
{cprintf("Û"); }}

for(int h=1;h<256;h++)
{textcolor(6);
cout<<"\n";
for(int k=1;k<=12;k++)
{cprintf("Û"); }}

for(int l=1;l<256;l++)
{textcolor(7);
cout<<"\n";
for(int z=1;z<=12;z++)
{cprintf("Û"); }}

for(int x=1;x<256;x++)
{textcolor(8);
cout<<"\n";
for(int c=1;c<=12;c++)
{cprintf("Û"); }}
getch();
}

Everything about that code is wrong. Don't use conio.h.
Last edited on
closed account (EhA4jE8b)
I made it right. I used this code:
The output filled the screen with 7 colors.

#include<conio.h>
#include<iostream.h>
void main()
{  
clrscr();for(int i=1;i<51;i++)
{textcolor(2);
cout<<"\n";
for(int j=1;j<=13;j++)
{cprintf("Û"); }
textcolor(3);
for(int a=1;a<=13;a++)
{cprintf("Û"); }
textcolor(4);
for(int s=1;s<=13;s++)
{cprintf("Û"); }
textcolor(5);
for(int d=1;d<=13;d++)
{cprintf("Û"); }
textcolor(6);
for(int f=1;f<=13;f++)
{cprintf("Û"); }
textcolor(7);
for(int g=1;g<=14;g++)
{cprintf("Û"); }}
getch();
}
Topic archived. No new replies allowed.