Post Contains:
- C++ code
- Line by line variable values and output
- Image view of code
- Image view of sample output of program
C++ Code:
#include<iostream>
using namespace std;
int main()
{
for(int i=0;i<=5;i++){
for(int j=0;j<=i;j++)
{
cout<<j;
}
cout<<endl;
}
return 0;
}
Line by line variable values and output
i=0
j=0
output
0
i=1
j=0 to j=1
output
0
0 1
i=2
j=0 to j=2
output
0
0 1
0 1 2
i=3
j=0 to j=3
output
0
0 1
0 1 2
0 1 2 3
i=4
j=0 to j=4
output
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
i=5
j=0 to j=5
final output:
0
0 1
0 1 2
0 1 2 3
j=0 to j=5
final output:
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
Image view of program:
c++ shape code to print right triangle using for loop |
Sample output image view:
sample output shape code to print right triangle using for loop |
thanx. this helped me alot :)
ReplyDeleteWelcome HLLNZ100 ..
DeleteAslam-U-Alaikum bhai.
Deletehow can I print M with stearic (*).
can u help me?
thax alot
ReplyDeleteCan anybody help me to solve this program
ReplyDelete*******
*
*
*
*
*
*
*
*
*******
plx giv me
ReplyDelete1
2 2 2
3 3 3 3 3
4 4 4 4 4 4
You Can Find Codes Like This Here.
Deletehttp://fahad-cprogramming.blogspot.com/p/c-shapes-code.html
#include
Deleteusing namespace std;
int main()
{
for(int i=0;i<=5;i++){
for(int j=0;j<=i;j++)
{
cout<<i;
}
cout<<endl;
}
return 0;
}
1. Write a program that prints the following pattern where n is taken as input:
ReplyDeleten = 2
1
21
n = 3
1
21
321
n = 4
1
21
321
4321
And so on
Write this code frd
DeleteFor(I=0;I<5;I++)
{
For(j=I;j>=1;j++)
{
Printf("%d",j);
}
Printf("\n");
}
dare make program that your output will look like this
ReplyDelete1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
How can I write a program that will let the user inter a number (i,e 4) and outputs the followings using a nested for loop?
ReplyDelete1
12
123
1234
123
12
1
another example say the user inters a number 2
1
12
1
Never mind, I figured it out :)
Deletedndu can put the answer of your question .
ReplyDeleteA solution to Dndu's question
ReplyDelete#include
using namespace std;
int main()
{
int num, out = 0;
cout << "Give a number: ";
cin >> num;
for (int i = 1; i <= 2*num-1; i++){
cout << 1 << " ";
for (int j = 2; j <= i && ((j <= num && i <= num) || (i > num && j <= 2*num-i)); j++)
{
out = j;
cout << out;
cout << " ";
}
cout << endl;
}
return 0;
}
A solution for papeeu's "challenge"
ReplyDelete#include
using namespace std;
int main()
{
int rows, out = 0, temp;
cout << "Give a number: ";
cin >> rows;
for (int i = 1; i <= rows; i++){
temp = i;
cout << i << " ";
for (int j = 1; j < i; j++)
{
out = temp + rows - j;
cout << out;
cout << " ";
temp = out;
}
cout << endl;
}
return 0;
}
This comment has been removed by the author.
ReplyDeleteWrite a C++ program that will print the pattern as shown below:
ReplyDeleteOutput:
*
***
*****
*******
*********
*********
*******
*****
***
*
Deleteusing namespace std;
int main()
{
char e=42;
for(int i=0; i<=5;i++){
for(int a=0;a<=i; a++)
{cout<<" * ";}
cout<<" "< 0; i--){
for(int a=0;a<i; a++)
{cout<<" * ";}
cout<<" "<<endl;
}
cout <<"\n programmed by @kangemah ...tweeter.........................."<<endl;
return 0;
}
how to print like this
ReplyDelete1
22
333
4444
55555
??
#include
Deleteusing namespace std;
int main()
{
for(int i=1;i<=5;i++){
for(int j=1;j<=i;j++)
{
cout<<i;
}
cout<<endl;
}
return 0;
}
plz give the code for following output.
ReplyDelete1
3 5
7 9 11
13 15 17 19
pls give code for the following output
ReplyDeleteA
A B
A B C
A B C D
A B C D E
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete****1
Delete***21
**321
*4321
54321
can u declare space instead of star?
import java.util.Scanner;
Deleteclass Task8{
public static void main(String[] args)
{
Scanner user_input=new Scanner(System.in);
System.out.println("enter number row :");
int col;
col = user_input.nextInt();
for(int i = 1; i <= col; ++i) {
for(int j = (col-1); j >= i; --j)
System.out.print(" ");
for(int k = 1; k <= i; ++k)
System.out.print(k);
System.out.println();
}
}
}
How to get this pattern
ReplyDelete1 1 1
2 2
3
How to get this pattern
ReplyDelete1 1 1
2 2
3
Hi can you answer a question from me? How do i do this by using for loop?
ReplyDeleteEnter a first number
Cin>>a;example is 1
Enter second number
Cin>>b;//example is 5
The out put should be
54321
4321
321
32
1
This comment has been removed by the author.
ReplyDeleteHey Help please
ReplyDeleteyes
ReplyDeleteLet start a program
ReplyDeleteIn array you enter 5 array and you enter number
What the number will be plus
hello,
ReplyDeletecan someone help me with this:
^^^^*
^^^**
^^a**
^*b**
**c**
^*d**
^^e**
^^^**
^^^^*
(^ is represented as space)
and can you recommend any websites that shows more example on adjusting the star pattern instead of just simple pattern.
thank you!
how to
ReplyDelete1
12
123
1234
1234
and
1234321
123 321
12 21
1 1
Design a complete C++ program to print out the outputs as shown below. The program must use
ReplyDeletenested for loop and if else statement.
* * * *
# # #
* *
#
i need this please urgent within 6 hours
ReplyDelete12345
2345
345
45
5
congrats
Deleteplxxxxxxx give me codd for this......
ReplyDelete1 2 3
5 10 15
25 50 76