Q1. WAPT: show the following pattern
_______$
______$$
_____$$$
____$$$$
___$$$$$
__$$$$$$
_$$$$$$$
$$$$$$$$
(If the user input is 8)
We take 3 loops; one for line number, one for the number of '_' and one for the number of '$' symbol. If we look closely, in line 1, we have 1 '$' and (81) '_'. In line 2, we have 2 '$' and (82) '_'. In general, line i has i '$' and (ni) '_' symbols. Hence the pattern follows upto the n'th line.
If there are any questions or doubts, feel free to email me at: [email protected]
_______$
______$$
_____$$$
____$$$$
___$$$$$
__$$$$$$
_$$$$$$$
$$$$$$$$
(If the user input is 8)
#include<iostream.h> int main() { int n; cin >> n; for (int i=1; i<=n; i++) //For number of lines { for (int j=1; j<=(ni) ;j++) { cout << "_"; } for (int k=1; k<=i; k++) { cout << "$"; } cout << endl; } return 0; }
We take 3 loops; one for line number, one for the number of '_' and one for the number of '$' symbol. If we look closely, in line 1, we have 1 '$' and (81) '_'. In line 2, we have 2 '$' and (82) '_'. In general, line i has i '$' and (ni) '_' symbols. Hence the pattern follows upto the n'th line.
If there are any questions or doubts, feel free to email me at: [email protected]
0 Comments On This Entry
Trackbacks for this entry [ Trackback URL ]
Tags
My Blog Links
Recent Entries

[C++] Answer to questions on Nested Loops
on Oct 03 2012 06:56 AM
Search My Blog
0 user(s) viewing
0 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)