Here are some extremely simple programs in C++ for absolute beginner students. I hope these would help them understand how nested loops work in programming. The required pattern of numbers to be printed on screen by a specific program is given before the source code to serve a problem statement.
1)
Required Pattern
1
12
123
1234
12345
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <iostream> using namespace std; int main() { int N = 5; int M = 1; for (int i = 0; i < N; i++) { for (int j = 1; j <= M; j++) { cout << j; } cout << endl; M++; } system("pause"); return 0; } |
2)
Required Pattern
12345
1234
123
12
1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <iostream> using namespace std; int main() { int N = 5; int M = N; for (int i = 0; i < N; i++) { for (int j = 1; j <= M; j++) { cout << j; } cout << endl; M--; } system("pause"); return 0; } |
3)
Required Pattern
1
21
321
4321
54321
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <iostream> using namespace std; int main() { int N = 5; for (int i = 0; i < N; i++) { for (int j = i+1; j > 0; j--) { cout << j; } cout << endl; } system("pause"); return 0; } |
4)
Required Pattern
54321
54321
54321
54321
54321
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <iostream> using namespace std; int main() { int N = 5; for (int i = 0; i < N; i++) { for (int j = N; j > 0; j--) { cout << j; } cout << endl; } system("pause"); return 0; } |
Enjoy!
If you can’t understand any step of any of these programs then please let me know via comments. I shall try my best to help you in understanding there execution.
will you please tell me the solution of this problem
*
* *
* **
* ***
* ****
* *****
* ******
* *******
#include
using namespace std;
int main()
{
int x,i,j;
cout <> x;
for(int i =1; i <=x; i++)
{
for(int j=1; j <=i; j++)
{
cout <<"*";
}
cout << "\n";
}
return 0;
}
Write a program that takes input of percentage from
a batch of total 21 students using FOR loop. When the
percentage is below 80, show “You are not eligible for
scholarship”, when percentage is 80 or above, display
“You are not eligible for scholarship”, at end show
“Invalid Input” to handle any other values. Use if elseif
else nested structure inside for loop.
Please help
#include
using namespace std;
int main()
{
int k=0,A=0,B=0,i,num,per;
cout<>num;
for(i=0; i<num; ++i)
{
k++;
cout<<"Enter the percentage of number "<<k<>per;
cout<<"percentage is"<<per<<"%"<=80)
{
cout<<"The student is elligable for the scholorship"<<endl;
A++;
}
else
{
cout<<"The student is not elligable for the scholorship"<<endl;
B++;
}
cout<<"—————————————————"<<endl;
}
cout<<"The number of elligabel students is="<<A<<endl;
cout<<"The number of unelligabl students is="<<B<<endl;
return 0;
}
Please tell me this program for nested loop
#
# #
# # #
# #
#
i want a program for out
1 2 3 4
11 12 13 14
112 113 114 115
113 114 115 116
Writing a source code using NESTED FOR-loop to print the following output.
*
***
*****
*******
*********
Here is the solution.
#include
using namespace std;
int main()
{
int x,i,j;
cout <> x;
for(int i =1; i <=x; i++)
{
for(int j=1; j <=i; j++)
{
cout <<"*";
}
cout << "\n";
}
return 0;
}
#include
using namespace std;
int main()
{
cout<<"Enter the number of lines you want to print on the screen"<>num;
for(i=1; I<=num; ++I)
{
for(j=i; j<=i; ++j)
cout<<"*";
cout<<endl;
}
cout<<"Composed by Dost Muhammad Khalil"
}
`
bro tell me code of this
1
21
321
4321
54321
What will be code of
A
Bc
Def
Ghij
Klmno
AsSalamM O ALaikuM! plz i want to know about code of this output.
************
*0*0*0*0*0*0
************
*0*0*0*0*0*0
************
plz help me!
#include
using namespace std;
void main(){
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 12; j++)
{
if (i % 2 == 1)
{
cout << "*";
}
else{
cout << "*" << "0";
}
}
cout << endl;
}
system("pause")
}
your program is not right. An error show in your program.
What about :
$*****
*$****
**$***
***$**
****$*
*****$
//Hell friend This will print the above pattern
#include
#include
using namespace std;
int main()
{
system(“color f2”);
for(int a=1; a<=6; a++)
{
for(int b=1; b<=6; b++)
{
if(a==b)
{
cout<<" $ ";
}
else{cout<<" * ";}
}
cout<<endl;
}
}
how to print out put on the screen this
123
456
789
only three row and three columen
int i,j,n=3,a=1;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
printf("%d",a);
a++;
}printf("\n");
}
#include
using namespace std;
int main()
{
for(int a=1; a<=9; a++)
{
if(a%3==1)
{
cout<<endl;
}
cout<<a;
}
}
How to print this with nested for loop…
#########
#### ####
### ###
## ##
# #
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
can anyone tell me the code for that program?
plz help me to program to simulate an analog watch (number 1 to 12 to be arranged in circular fashion with all the three pointers for second minutes and hours ) on the screen. Use nested for loops.
Use (.) dot for seconds pointer
Use (*) star for minutes pointer
Use (#) hash for hours pointer.
sir how to solve diamoind shape question in c++
#include
using namespace std;
int main()
{
for(int a=1;a=a;c–)
{
cout<<" ";
}
for(int b=1;b<=a;b++)
{
cout<<"* ";
}
cout<<"\n";
}
for(int a=1;a<=5;a++)
{
for(int c=0;c<=a;c++)
{
cout<=a;b–)
{
cout<<"* ";
}
cout<<"\n";
}
return 0;
}
use of nested loop will help you solve any kind of pattern but first understand the concept of
nested loop that how it work
Ask the user to enter a number then display this according to that number:
*****
* *
* *
* *
* *
*****
How to write ?
1
1 1
1 1 1
1 1 1 1
#include
#include
voidmain()
{
int r,c;
clrscr();
for(r=1;r<=4;r++)
{
for(c=1;c<=r;c++)
cout<<"1";
}
cout<<"endl";
getch();
}
#include
#include
using namespace std;
int main()
{
int a=1;
for(int b=1;b<=4;b++)
{
for(int c=1;c<=b;c++)
{
cout<<" "<<a;
}
cout<<endl;
}
getch();
return(0);
}
//Here's the code in c++ for your above pattern
*****
* *
* *
* *
***** anyone please ya kisi aur se is program ki coding mungwa day plz urgently for loop main
1 2 3
4 5 6
7 8 9
That is pattern but we need to print 3rd column only….. How it will??
hi pleas tell me how can I use nested loop in Che’s problem pleas send me solve programs By chess method in c++
Write a program to produce the following output: PLZ
ABCDEFGFDCBAA
ABCDF FEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
how can i print out our name with stars(*)?
how to print
0 0 0 0 0
1 2 3 4
4 6 8
9 12
16
using loop!
2 5 7 12
19 31 50
131 222 353 575
plz help me to make that program
how can print bellow diagram by using nested loop
****
****
****
#include
#include
voidmain()
{
int r,c;
clrscr();
for(r=1;r<=3;r++)
{
for(c=1;c<=4;c++)
cout<<"*";
}
cout<<"endl";
getch();
}
how to make such a pattern using for loop
number is as choice
t
tt
ttt
tttt
ttttt
ttttt
tttt
ttt
tt
t
int main()
{
int i;
for(i=1;i0;j–)
{
cout<<"t";
}
cout<0;k–)
{
for(int j=k;j>0;j–)
{
cout<<"t";
}
cout<<endl;
}
getch();
return 0;
}
Write a program which is show following output using loop.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
//Friend, I’ve given you the code for your code
//Hope you’ve been beneficial
#include
#include
using namespace std;
int main()
{
char ab=’t’;
for(int a=1;a<6;a++)
{
for(int b=1;b<=a;b++)
{
cout<<" "<<ab;
}
cout<=1;c–)
{
for(int d=1;d<=c;d++)
{
cout<<" "<<ab;
}
cout<<endl;
}
getch();
return(0);
}
//Sorry for my first code, there’s a silly mistake
#include
#include
using namespace std;
int main()
{
char ab=’t’;
for(int a=1;a<6;a++)
{
for(int b=1;b<=a;b++)
{
cout<<" "<<ab;
}
cout<=1;c–)
{
for(int d=1;d<=c;d++)
{
cout<<" "<<ab;
}
cout<<endl;
}
getch();
return(0);
}
plz tell me how to print * this pattren in devc++ using nested for loop?????
* *
* * *
#include
using namespace std;
int main()
{
for(int i=0;i<=2;i++){
for(int j=0;j<=2;j++)
if(i==2||i==0&&j==1||i==0&&j==2)
{
cout<<"*";}
else
cout<<"";
cout<<"\n";
}
}
plz help me dear
Q) take one number from user and display star of that number?
1
10
101
1010
kindly tell me how to print this by nested for loop
plzz find me a solution
BBBBBBBBB
.BBBBBBB
..BBBBB
…BBB
….B
help me plzz.
i want to draw this
#####*#####
####*#*####
###*###*###
##*#####*##
#*#######*#
*#########*
#include
using namespace std;
int main()
{
int x=5,y=1,z=1,n,r=5;
for(int i=1;i<=6;i++)
{
for(int j=1;j<=x;j++)
{
cout<<"#";
}
x–;
for(int k=1;k<=y;k++)
{
cout<<"*";
}
for(int l=1;l<z;l++)
{
cout<<"#";
//z=1;
}
z+=2;
for(int m=1;m<=n;m++)
{
cout<<"*";
n=1;
}
n+=1;
for(int a=1;a<=r;a++)
{
cout<<"#";
}
r-=1;
cout<<endl;
}
}
#####**#####
####*##*####
###*####*###
##*######*##
#*########*#
*##########*
this is what i get when this is run which is fine, but it does not start with #####*##### and it would only run by changing x- to x– or x-=1 as i am a complete beginner i would be happy if you could explain the for loops so i can understand what is going on
10 10 10 10 10 10 10 10 10 10
9 9 9 9 9 9 9 9 9
8 8 8 8 8 8 8 8
7 7 7 7 7 7 7
6 6 6 6 6 6
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
Plz write programm for this plz plz
#include
using namespace std;
int main ()
{
int num=9;
for (int i=1;i<=10;i++)
{
cout << "10" << " ";
}
cout <=1;j–)
{
for (int k=1;k<=j;k++)
{
cout << num << " ";
}
cout << endl;
num–;
}
return 0;
}
My program
12345
123
1
51311
311
1
#include
using namespace std;
int main()
{
for(int i=10; i>=1; i–)
{
for(int j=0; j<i; j++)
cout<<i;
cout<<endl;
}
}
Write a program that inputs following
1
222
33333
4444444
555555555
#include
using namespace std;
int main()
{
for(int i=1; i<=5; i++)
{
for(int j=0; j<i; j++)
cout<<i;
cout<<endl;
}
}
please tell me hoe to do it?
1******
12*****
123****
1234***
12345**
123456*
1234567
#include
using namespace std;
int main()
{
int n=5;
int m=1;
for (int i=1;i<=7;i++)
{
for (int j=1;j<=m;j++)
{
cout <=i;k–)
cout << "*";
cout << endl;
m++;
}
}
1******
12*****
123****
1234***
12345**
123456*
1234567
Can someone help me with the following one
3
3
12345
3
3
#include
#include
using namespace std;
int main()
{
int c,r;
for(c=3; c<=3; c++)
{
cout<<c<<endl;
}
for (r=1; r<=5; r++)
{
cout<<r;
}
for(c=3; c<=3; c++)
{
cout<<"\n"; //for new line
cout<< c;
cout<< "\n"; //for new line
cout<<c;
}
getch();
return 0;
1 2 3 4 5
1 3 5 7 9
1 4 7 10 13
what will be the code using nested loop.
Mahi if get the code plz snd me too.
Required Pattern
*****
*****
*****
*****
*****
#include
#include
#include
void main(void)
{
clrscr();
for( int i =1 ; i <=5 ; i ++)
{
cout<<" \n "; // for a new line
for( int j =1 ; j <=5 ; j ++ )
{
cout<<" * ";
}
cout<<" \n ";
}
getche();
}
#include
using namespace std;
main()
{
for(int i=1;i<=4;i++)
{
for(int j=1;j<=i;j++)
{
cout<4;k–)
cout<<"*";
cout<<endl;
}
}
}
}
int main()
{
int i,p;
for (i=1; i<=5; i++)
{
for(p=1; p<=5; p++)
cout<<"*";
cout<<"\n"; //new line;
}
return 0;
}
Please solve it
1
23
456
78910
#include
#include
#include
using namespace std;
int main()
{
int a,b=0,c,d,n=1;
for(int i=1;i<5;i++)
{
for(int j=1;j<=i;j++)
{
cout<<n;
n++;
}
cout<<endl;
}
return 0;
}
..
can you tell me how write the program hallow diamond
How to create pajama shapes using two triangles
Write a c++ programs that use two nested loops to generate the following input
1 2 3 4=10
5 6 7 8=26
9 10 11 12=42
13 14 15 16=58
plz tell me its urgent
just use printf or cout. Enjoy it !!!!!
Logic will remain same.
Write: printing purpose and
WriteLine: printing+new line.
for (int i = 1; i <= 13; i+=4)
{
int sum=0;
for (int j = i; j <=i+3; j++)
{
sum+=j;
if (j == i + 3)
{
Console.Write(j.ToString() + "=" + sum.ToString());
}
else
{
Console.Write(j.ToString() + " ");
}
}
Console.WriteLine();
}
#include
#include
#include
using namespace std;
int main()
{
int a,b=0,c,d,n=1,sum=0;
for(int i=1;i<5;i++)
{
for(int j=1;j<=4;j++)
{
sum=sum+n;
cout<<n;
n++;
}
cout<<"="<<sum;
cout<<endl;
sum=0;
}
return 0;
}
eroplan print kro by using for loop in c plus plus…phr pta chlay apka
*
*
*
*
*
how to print this with recursion??
plz tell me how to make +,-,%,/ shapes by using asterics in c++
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
please give me the solution
This structure is known as Pascal Triangle and it has a specific coding. Here’s the coding :
#include
#include
long calc( int );
int main()
{
int i,j,row,pas;
printf(“Enter no. of rows in pascal triangle : “);
scanf(“%d”, &row);
for(i=0; i<row; i++)
{
for(j=0; j<=(row-i-1); j++)
printf(" ");
for(j=0; j<=i; j++)
{
pas=calc(i)/(calc(j)*calc(i-j));
printf("%ld ",pas); //take single space
}
printf("\n");
}
getch();
return 0;
}
long calc( int num)
{
int x;
long res=1;
for(x=1; x<=num; x++)
res=res*x;
return (res);
}
In main, formula of pas is in the form of factorial formula.
i caant undrstand??what is m and n??
1
212
32123
4321234
543212345
4321234
32123
212
1
how we can do it
Plz give your program
code
Write a program using nested loops which generate the following output:
(1,1)(1,2)(1,3)
(2,1)(2,2)(2,3)…
The value of the first number has to be taken from the user.
How i can solve this?
Good question
how to draw only using min 3 loops no conditions
12345
23451
34512
45123
51234
just use printf or cout. Enjoy it !!!!!
Logic will remain same.
Write: printing purpose and
WriteLine: printing+new line.
int ii,jj,kk;
for (ii = 1; ii <= 5; ii++)
{
for (jj = ii; jj <= 5; jj++)
{
Console.Write(jj.ToString());
}
for (kk = 1; kk < ii; kk++)
{
Console.Write(kk.ToString());
}
Console.WriteLine();
}
please solve this pattren
1
21
321
4321
54321
just use printf or cout. Enjoy it !!!!!
Logic will remain same.
Write: printing purpose and
WriteLine: printing+new line.
for (int i=1; i = 1; j–)
{
Console.Write(j);
}
Console.WriteLine();
}
i have to print a hollow diamond shape but length should be greater than height
plz tell me how to print
*******
* *
* *
* *
*******
this program is very simple and is possible on nested loop;
teacher give it us today in viva
Then plz post the answer
{
//print the following program use cout statment ?
/*cout<<"*******"<<endl;
cout<<"* *"<<endl;
cout<<"* *"<<endl;
cout<<"* *"<<endl;
cout<<"*******"<<endl;*/
// following program use nested loop
int i;
for(i=1;i<=7;i++)
{
cout<<"*";
}
cout<<endl;
{
for(int j=1;j<=3; j++)
cout<<"* *"<<endl;
}
for(i=1;i<=7;i++)
cout<<"*";
return 0;
}
#include
using namespace std;
int main ()
{
int i, j;
for(i=1; i<=2; i++) {
cout<<"********\n";
for(j=1; j <=3; j++){
cout<<"**\n";
} cout<<"********\n";
break;
}
return 0;
}
plz tell me how to print
1
222
33333
4444444
555555555
just use printf or cout. Enjoy it !!!!!
Logic will remain same.
Write: printing purpose and
WriteLine: printing+new line.
int u = 0;
for (int i = 1; i < 5; i++)
{
for (int j = 1; j <= u+i; j++)
{
Console.Write(i);
}
u = u + 1;
Console.WriteLine();
}
#include
using namespace std;
void main()
{
int row,st,space,row1,n=1;
for(row=1;row<=5;row++){
for( st=1;st<=row;st++){
cout<<n;
}
cout<<endl; n++;
//dec++;
//inc++;
}
cin.get();
}
#include
#include
main()
{
int a,b;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
{
printf("%d",a);
}
printf("\n");
}
}
Write a c++ programs that use two nested loops to generate the following input
1 2 3 4=10
5 6 7 8=26
9 10 11 12=42
13 14 15 16=58
How i can solve this???
Input a four digit numbers,for exanples 1234. print the number in reverse irder i.e 4321 on dev c++
salam…here is a pattern to solve ur qs4n
#include “stdafx.h”
#include
using namespace std;
int main()
{
int number, reverse = 0;
cout<> number; // Taking Input Number in variable number
for( ; number!= 0 ; )
{
reverse = reverse * 10;
reverse = reverse + number%10;
number = number/10;
}
cout<<"New Reversed Number is: "<<reverse<<endl;
system("pause");
return 0;
}
main()
{
int a,b,c,d;
cin>>a; //1234
b=a/1000;
a=a%1000;
c=a/100;
a=a%100;
d=a/10;
a=a%10;
cout<<a<<d<<c<<b;
}
output:
4321
please solve it
1 2 3 4
5 6 7 8
9 10 11 12
please print it
1111
1111
1111
1111
How to do this programme?
URGENT!!!
#include
#include
using namespace std;
int main()
{
for(int i =0;i<4;i++)
{
for(int a=0;a<4;a++)
{
cout<<"1";
}
cout<<"\n\n";
}
getch();
}
I used this code to implement this shape
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
I must now produce this pattern
* * * . * * *
* * * . * * *
* * * . * * *
. . . . . . .
* * * . * * *
* * * . * * *
* * * . * * *
please help?
I did it!
for (int row = 0; row < 7; row++) // Define amount of rows
{
for (int col = 0; col < 7; col++) // Define number of columns within each row
{
if (row == 3 || col == 3)
{
cout << ". ";
}
else
{
cout << "* "; // Print a "*" each time the
}
}
cout << :endl;
}
PLEASE TELL ME HOW TO PRINT:–
********
*** ***
** **
* *
* *
** **
*** ***
********
plz tel me how to print following program
*111111
**22222
***3333
****444
*****55
******6
Have you given it a try yourself? Please show the code that you have so far and we can move from that point froward.
Thanks for visiting btw 🙂
in your coding there is a word cout. what is the function of it?
*/Please try this
#include “stdafx.h”
#include
using namespace std;
void main()
{
int i,j,k;
for(i=0;i<=6;i++)
{
for(j=1;j<=i;j++)
cout<<j;
cout<<endl;
for(k=1;k<=6+1-i;k++)
cout<<"*";
}
}
****
* *
* *
****
plz tell me how its posible with nested loop
#include
using namespace std;
int main()
{
for(int i=0;i<=4;i++){
for(int j=0;j<=4;j++)
if( i==0||i==4||i==0&&j==2||j==3||i==4||j==1)
{
cout<<"*";}
else
cout<<" ";
cout<<"\n";
}
}
how to do this ?? help please !!
1
212
32123
4321234
543212345
4321234
32123
212
1
#include
int main ()
{
int a;
int b;
for(a=0;a=0;b–) {
printf(” “);
}
for(b=0;b=a;b++) {
printf(“%d”,a);
}
}
printf(“\n”);
}
Nicely written article but it is missing some detailed explanations. If anyone like to see details then they can find it there http://www.hellgeeks.com/loops/
Can anyone do this?
Using For Loop, While Loop and DoWhile Loop, create a program that will ask the user to input any number from 1-99. The input of the user will serve as the starting number of the output until it reach 100.
Sample Output:
Enter number from 1-99: 40
40 41 42 43 44 45 46 47 48 49 50 ……..98 99 100
Would you like to continue? (y/n)
Note: Any input other than 1-99 should be “invalid input” and should ask again to enter number from 1-99. Would you like to continue (y/n)? question should still be posted every after the display of the output numbers. If user input y or Y, display “Welcome back” and go back to main, if n or N display “Thank you” and exit program. Any other input, display “Invalid input” and go back to the question would you like to continue? (y/n)\
Please help me to draw this pattern
***************
***************
* *
* *
* *
***************
***************
help me to display the following result
BBBBBBBBB
BBBBBBB
BBBBB
BBB
B
#include
using namespace std;
int main(){
int x=5;
int i,j;
for(i=1;i<=5;i++)
{
for(j=0;j<x;j++)
cout<<"B";
cout<<endl;
x–;
}
return 0;
}
Can anyone tell me how to do this example
Design a program that is capable of calculating total of five subjects marks, each of 100 marks. The program will run as long as the user wishes but will work once at least without asking user’s permission.
Use Nested loop to design the program.
The inner loop will calculate total of 5 subject marks. Do not use 5 variables for 5 subjects.
Use outer loop to find if user wishes to continue.
Validate that user enters marks of each subject between 1 to 100
int n=5
int m=n
what does it mean:?
and i and j is not defined in int so how it can be used in loops:???? plzz tell me .,.,., em a beginner
Sorry for late reply Talha.
int N = 5;
defines an integer variable named “N” and sets it equal to 5.
int M = N;
defines another integer variable named “M” and sets it equal to the value of the variable N. As we have just assigned a value of 5 to N, it is equivalent to the following statement:
int M = 5;
But a slight benefit in doing it the way I have done is that, if on a later time, you decide that both M and N should be initialized at a value of 10 instead of 5, then you will have to make this change at one place in your source code. If you define both variables independently then you will have to make that change at two places. This looks like a very small benefit in this simple example. But if you make it your habit to do things in such centralized ways, then you will see that it will save you from a lot of trouble when you move on to reasonably more complex and longer programs.
Now lets look at your second question. Why do you think that i and j are not defined as int variables? They are clearly defined in the first line of their respective for loops. In the parenthesis that follow the “for” keyword, you are allowed to put any three C++ statements separated by semicolons. There is no restriction from compiler on what kind of operations could be performed in those statements. Therefore, in these examples, I am defining variables in first of those three statements.
Hope it helps. Thanks for visiting and best of luck for your newly started programming journey 🙂
1
212
32123
4321234
543212345
4321234
32123
212
1
plz help me to do it
any idea about this please gays
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9
how to print
* * * *
* * *
* *
*
#include
using namespace std;
int main()
{
int i=5;
int j;
while(i>0)
{
j=i;
while(j>0)
{
cout<<"*";
j=j-1;
}
cout<<endl;
i=i-1;
}
return 0;
}
#include
#include
void main()
{
clrscr();
int i,j;
for(i=4;i>=1;i–)
{
for(j=1;j<=i;j++)
cout<<"*";
cout<<endl;
}
getch();
}
please how to combine all this pattern and print it..pleaseeeeeeeeeee….
*
**
***
****
*****
#
###
#####
#######
@
@@
@@@
@@@@
@@@@@@
please tell me how print this
n = 2
1
21
n = 3
1
21
321
n = 4
1
21
321
4321
n is taken input frm user
First try it yourself. Post what you have come up with here. Then I will correct any mistakes or errors that you might have in your code. In this way, you will learn much more than simply copying the code 🙂
how to print
111
22
3
|_
| |_
| | |_
| | | |_
| | | | |_
| | | | | |_
how to print this
well … make the outer loop iterate for 6 times, and the inner loop to iterate for 2 times in first iteration of the outer loop and progressively reach 7 iterations by the last iteration of the outer loop. Place a check (if statement) in the body of inner loop that prints an underscore (_) if it is the last iteration of the inner loop and a pipe (|) otherwise.
I hope these hints will be enough for you to write your required program. Try your best and If you are still confused about some specific step then paste the code that you are able to come up with here and I shall try to correct any of your mistakes 🙂
And, thanks for visiting 🙂
****
* *
****
*
* * *
* * * * *
* * * * * * *
please send me this solution
#include
#include
void main()
{
int a=5;
int b=a;
for(int c=0;c<a;c++)
{
for(int d=1;d<=b;d++)
{
cout<<"*";
}
cout<<endl;
b–;
}
}
#include
#include
void main()
{
int a,b;
cout<<"enter the value of a:="<<endl;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
{
cout<<"*";
}
cout<<endl;
}
getch()
}
#include
#include
void main()
{
clrscr();
int i,j,n;
cout<<"enter any number to find its pattern"<>n;
for(i=1;i<=n;i++)
{
for(j=0;j<=i;j++)
{
cout<<"*";
}
How to print this.
5
7 9
9 11 13
11 13 15
13 15 17 19
{&&&&&&&&&&
& &
& &
& &
&}
i want dis to create ???????????????????//
how should i??using nested loops
How to print stars equal to the number entered?
run a loop equal to the number entered and output a star in each iteration. it is so simple …
How should i creat dis
&&&&&&&
& &
& &
&
I can’t detect some regular pattern in these lines. can you please tell in some more detail what could be some other legitimate outputs. Then I may be able to help you better.
if it has some white spaces on the left side of lines which are not showing here, then please repost it by enclosing it within
[codesyntax lang=”php”]
[/codesyntax]
tags.
Thanks
this is the continuation:
for (int l=(N-1)/2; l>=1; l–) //l=line number after mid to end in descending order after mid.
{ //so if line mid=3, the line after it is line 2 and then line 1.
for (int s=1; s<=space_2; s++) //s=spaces on each line l.
cout<<" ";
for (int a=(space_2)+1; a<=(N-space_2); a++) //a=place os asterisks on each line l.
cout<<"*";
cout<=1; l–) //l=line number after mid to end in descending order after mid.
{ //so if line mid=3, the line after it is line 2 and then line 1.
for (int s=1; s<=space_2; s++) //s=spaces on each line l.
cout<<" ";
for (int a=(space_2)+1; a<=(N-space_2); a++) //a=place os asterisks on each line l.
cout<<"*";
cout<<endl;
space_2+=1; //updating space_2.
}
But the shape above is ot how i meant it. i meant them to be aligned in the middle.
thank you.
humm .. looks nice. good effort! however I was not able to compile your program mainly due to this line:
[codesyntax lang=”cpp”]
cout<=1; l
I meant something like this
*
***
*****
***
*
el hamdulellah using this code, it was printed but I don’t know if there’s a simpler way because it seems complicated:
int mid=(N+1)/2; //the line in the middle of the rhomboid.
int space=(N-1)/2; //the number of spaces before the ‘*’. Is to be used for line 1 of the rhomboid to line mid.
int space_2=1; //to be used for spaces before’*’ for lines after line mid untill the last line.
for (int l=1; l<=mid; l++) //l=line number from 1 to mid.
{
for (int s=1; s<=space; s++) //s=spaces on each line l.
cout<<" ";
for (int a=space+1; a<=(N-space); a++) //a=place of asterisk on each line 1.
cout<<"*";
cout<<endl;
space-=1; //updating space.
}
Yes .. I shall try my best to help you. Can u please tell me for a given value of N, say N=5, what should be the output of this program?? I mean the correct output as asked in the problem statement. Currently for N=5 it prints 5 lines containing 5 asterisks each like this:
[codesyntax lang=”cpp”]
*****
*****
*****
*****
*****
[/codesyntax]
do you want to print:
[codesyntax lang=”cpp”]
*
***
*****
***
*
[/codesyntax]
or something else for N=5??
and … Thanks for visiting!
I am trying to do a program that prints asterisks in the shape of a diamond with N lines and this where i got so far. Is it possible to teach me how to continue without telling me the answer. Thank you.
for (int k=N; k>0; k–)
{
for (int i=1; i<=N; i++)
cout<<"*";
cout<< endl;
}
how to make nested for loop program for this
A
B C
C D E
D E F G
E F G H I
please help
Have you attempted it yourself?? what specific problem do you have??
Pease first show me what you have come up with and then I shall try my best to help you correct your mistakes 🙂
However if you don’t know how to generate successive alphabets in a program then I can give you a hint in this regard.
Alphabets ‘A’ to ‘Z’ correspond to ASCII values 65 to 90 respectively. It means that if you assign a number in this range to a variable of type ‘char’ and then output this variable to screen then the alphabet corresponding to that number will be printed.
Look at this simple example program. It prints all capital alphabets from ‘A’ to ‘Z’ on the screen.
char ch;
for ( int i=65; i<=90; i++ ) { ch = i; cout << ch << endl; } Now that you have the fundamental skill to get the required output, please try to design the required nested loops yourself and in case of any problem show me your code and I shall try to help you 🙂 Thanks for visiting though!!
what will be the program for followiing output by using nested loop in c++.
5 1
5 2
5 3
5 4
4 1
4 2
4 3
3 1
3 2
2 1
its my assignment urgent reply..
sorry for the late reply 🙂
plz first attempt it yourself. if you still can’t find a solution or get stuck in an error that you can’t resolve then let me know by showing your code and i shall try to help you ..
Thanks!!
PLEASE TELL ME HOW TO PRINT:
1
212
32123
4321234
543212345
PLEASE!!!!!!!!!!!!! ITS VERY URGENT.
what you have come up with till now?? first show me your attempt. and tell me if you are facing difficulty with any specific step of the program ..
Thanks!!!
oh. .thank’s
i thought it could be a error!
I’m a second year, com.sci.
I hope , i can learn m0re about c++,
thank u very much,,
🙂
0n every sample pr0gram,
Why those i&j were n0t declared ,, it could have a error’ runing the program!
Hi nathaniel,
can u see the statements like int i=0, int j=0 as the first statements in the corresponding for loops?? They are actually declarations of these variables. the first of three statements in a for loop’s header is executed once at the beginning of the loop. so it causes the variable to be declared, defined and initialized properly before it is used so it doesn’t cause any error in the execution of the program. Hope you got it. if you still have any confusion then please follow back!!
Thanks for the comment.
oh. .thank’s
i thought it could cAuse an error!
Very sorry, ,
I’m a second year, com.sci. StudEnt,
I hope , i can learn m0re about c++,,
thank u very much sir,,,
🙂
I want pakistan flag code but i dont have a accurate code please help me to create that code.
Mine code is this…
#include
using namespace std;
int main()
{
for(int i=0;i<=15;i++)
{
for(int j=1;j<=40;j++)
{
system("color 02");
if(/*borders*/i==1||j==1||i==15||j==40||
/*Moon*/i==5&&j==29||i==5&&j==28||i==6&&j==27||i==7&&j==26||i==8&&j==26||i==9&&j==27||i==10&&j==28||i==10&&j==29||
/*star*/i==6&&j==31||i==7&&j==31||i==8&&j==31||i==7&&j==30||i==7&&j==32
)
{
cout<=1&&j<=11)
{
cout<<"/";
}
else{
cout<<" ";
}
}
cout<<endl;
}
for(int a=1;a<=9;a++)
{
cout<<"##"<<endl;
}
system("pause");
return 0;
}
You have a mistake in your 3rd example, N should be 5.
oh yes … and thank you very much for mentioning. i have just corrected it. Actually before writing this post, I was experimenting with my these programs to check whether they work as expected for other values of N, too. Probably i copied the source code in such a situation.
Anyhow, I am sorry for the mistake and thank you for indicating it!!!!!!!
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
plz help me to make that program
#include….
main()
{
clrscr();
int i,j;
for(i=1;i<=4;i++)
{
for(j=i;j<=4+i; i++)
{
cout<<j<<" ";
}
cout<<"\n";
}
getch()
}
i have to print a hollow diamond stars please help me
i++ you should change in j++
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
printf("%d",i+j-1);
}
printf("\n");
}
anas bhai plz tell me the code and logic of this programr
rhombus pattern with stars using for loop
how can i write this program ?? Print this value by using nested loop in C++
2471116
3581217
4691318
57101419
68111520
kindly tell me how to print bellow diagram by using nested loop
* * * * *
* *
* *
* * * * *
m very thankful to you