Question:
Write programs using nested loops to produce the following design: * * * * * * * * *
Answer:
#include <iostream.h><br><br>int main ()<br>{<br> int n;<br> cout << "Enter the number if levels you want ";<br> cin >> n ; <br> for (int i=1;i<=n;i++){<br> if(i%2!=0){<br> //cout << "i = " << i << " ";<br> for(int j=1;j<=i;j++){<br> cout << "*";<br> }<br> cout << " ";<br> }<br> }<br>}<br> Source: CoolInterview.com
Answered by: Venkataramana | Date: 9/14/2008
| Contact Venkataramana
cout<<" ";<br>for(int i =1 ; i<=3;i++)<br>{<br>for( int j=0; j<i;j++)<br>cout<<"*";<br>cout<<" ";<br>}<br> Source: CoolInterview.com
Answered by: akhila | Date: 9/15/2008
| Contact akhila
#include<iostream.h><br>int main()<br>{<br>int n,k=-1;<br>cout<<"Enter till how many levels the stars must be printed : ";<br>cin>>n;<br>for(int i=1;i<=n;i++)<br>{<br>k=k+2;cout<<" ";<br>for(int j=1;j<=k;j++)<br>cout<<"* ";<br>}} Source: CoolInterview.com
Answered by: lokesh | Date: 9/29/2008
| Contact lokesh
void main (void)<br>{ <br>for(int i =1 ; i<=3;i++)<br>{<br> for( int j=0; j<(2*i-1);j++)<br> { <br> cout<<"*";<br> cout<<" ";<br> }<br> cout << " ";<br>}<br>} Source: CoolInterview.com
Answered by: Namrata Bothra | Date: 9/30/2008
| Contact Namrata Bothra
int main(void)<br>{<br> int i, j, n;<br> for(i = 0; i < 3; i++) {<br> n = 2 * i + 1;<br> for(j = 0; j < n; j++)<br> cout << "* ";<br><br> cout << endl;<br> }<br> return 0;<br>} Source: CoolInterview.com
Answered by: Stanley Ni | Date: 10/3/2008
| Contact Stanley Ni
#include<iostream.h><br>#include<conio.h><br>main()<br>{<br>int n;<br>cout<<" Enter tne no of stars to be printed : ";<br>cin>>n;<br>for(int i=0;i<n;i++)<br>{<br>cout<<"*";<br>}<br>getch();<br>}<br> Source: CoolInterview.com
Answered by: Anandh | Date: 10/10/2008
| Contact Anandh
#include <iostream.h><br>void main()<br>{<br> int i,j,n;<br> cout<<"Enter the no. of rows to be printed: ";<br> cin>>n;<br> for(i=0;i<n;i++)<br> {<br> for(j=1;j<=(2*i)+1;j++)<br> {<br> cout<<"* ";<br> }<br> cout<<" ";<br> }<br>} Source: CoolInterview.com
Answered by: C.R.Lakshmi | Date: 10/29/2008
| Contact C.R.Lakshmi
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|