+ 3
Code for following output * * * * * * * * * using nested loops
6 ответов
+ 7
int n = 3;
for(int i = 1; i < n * 2; i++){
int stars = i > n ? n * 2 - i : i;
for(int s = 0; s <= n - stars; s++){
cout<< " ";
}
for(int s = 0; s < stars; s++){
cout<< "* ";
}
cout<<endl;
}
+ 1
I've created this
int n;
start:
cout<<"\nEnter the number of lines (odd numbers): ";
cin>>n;
int m=n;
if(n%2==0)
{cout<<"Invalid choice.Try again.";
goto start;}
for(int i=1;i<=m/2+1;i++)
{
for(int k=1;k<=n/2;k++)
cout<<" ";
for(int j=1;j<=i;j++)
cout<<"* ";
cout<<endl;
n-=2;
}
//Next half
n=(m/2);
int o=n;
for(int a=1;a<=o;a++)
{
for(int b=1;b<=a;b++)
cout<<" ";
for(int c=1;c<=n;c++)
cout<<"* ";
cout<<endl;
n--;
}
0
#Max Adam
Actually I want to input number of lines.. then if I input 7 there comes 13 lines..
0
can you help me in learning c++ I am beginer in this field plz help me I am thanful to you for that.
0
can u help me atif iqbal
- 4
#include <iostream>
using namespace std;
int main()
{
for(int a=1; a<=5;a=a+5){
for(int i=1;i<=5 ;i++){
if(i==1){
cout<<" "<<" "<<"*"<<endl;
}
if(i==2){
cout<<" "<<"*"<<" "<<"*"<<endl;
}
if(i==3){
cout<<"*"<<" "<<"*"<<" "<<"*"<<endl;
}
if(i==4){
cout<<" "<<"*"<<" "<<"*"<<endl;
}
if(i==5){
cout<<" "<<" "<<"*";
}
}//inner for loop
}//outer for loop
return 0;
}
//Works well in Code-blocks