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: navking.venkat7@gmail.com
_______$
______$$
_____$$$
____$$$$
___$$$$$
__$$$$$$
_$$$$$$$
$$$$$$$$
(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: navking.venkat7@gmail.com
0 Comments On This Entry
Trackbacks for this entry [ Trackback URL ]
← March 2015 →
S  M  T  W  T  F  S 

1  2  3  4  5  6  7 
8  9  10  11  12  13  14 
15  16  17  18  19  20  21 
22  23  24  25  26  27  28 
29  30  31 
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)
Categories
