Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Write a program for following output using while loop

+13 votes
asked Jul 30, 2019 by Mohana 1 flag
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
(If the range is 5)

13 Answers

–1 vote
answered Jul 31, 2019 by Swetha Vedhagiri (280 points)
#include <stdio.h>

int main()
{
    signed int i,j;
    for(i=5;i>=(-5);i--)
    {
        for(j=5;j>=abs(i);j--)
        {
            printf("*");
        }
        printf("\n");
    }

    return 0;
}
commented Aug 1, 2019 by anonymous 1 flag
Outer loop runs 11 times. There are only 9 lines in output.
0 votes
answered Jul 31, 2019 by keerthanav666 (300 points)
#include<stdio.h>
int main()
{
    int i,j,n;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
        {
        printf("* ");
        }
        printf("\n");
        }
    for(i=n;i>1;i--)
    {
        for(j=1;j<i;j++)
        {
            printf("* ");
        }
        printf("\n");
    }
    return 0;
}
0 votes
answered Aug 1, 2019 by kuelf
edited Aug 8, 2019
cin>>range;

string s = "*************";

for(int i = 1; i<range*2; i++) {

cout<< string(s.begin, s.begin + ( i - 2*(i%range)*(i/range) )  )  <<endl;

}
commented Aug 8, 2019 by Loki (1,600 points)
what sort of answer is this
commented Aug 8, 2019 by anonymous
Edited..............
0 votes
answered Aug 2, 2019 by Abhijit
#include <stdio.h>

int main()
{
    int i,j,n=5;
    i=1;
    while(i<=n)
    {
        j=1;
        while(j<=i)
        {
        printf("* ");
        j++;
        }
        printf("\n");
        i++;
        }
    i=n;
    while(i>1)
    {
        j=1;
        while(j<i)
        {
            printf("* ");
            j++;
        }
        printf("\n");
        i--;
    }
    return 0;
}
0 votes
answered Aug 2, 2019 by Mayuri Shitole (140 points)
#include <stdio.h>

int main()
{
    int i,j,k;
    
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=5;j++)
        if(j<=i)
    printf("*");
    //else
    printf("\n");
    
    }
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=5;j++)
        if(j>=i)
    printf("*");
    //else
    printf("\n");
    
    }
  
    
    return 0;
}
0 votes
answered Aug 2, 2019 by anonymous
#include <stdio.h>

void main(void)

{

  int i,j,k,range;

  printf("\nEnter range: ");

  scanf("%d",&range);

  i=0;

  j=1;

  while((i+=j) > 0)

  {

    for(k=0;k<i;k++) printf("*");

    printf("\n");

    if(i==range) j=-1;

  }

}
0 votes
answered Aug 3, 2019 by Aishwary Kumar (150 points)

#include <stdio.h>

int main()
{
    signed int i,j;
    for(i=5;i>=(-5);i--)
    {
        for(j=5;j>=abs(i);j--)
        {
            printf("*");
        }
        printf("\n");
    }

    return 0;
}

0 votes
answered Aug 3, 2019 by manapati rohit
#include <stdio.h>
int main()
{
for(int i=0;i<5;i++)
{
    for(int j=0;j<=i;j++)
    {
        printf("*");
    }
    printf("\n");
}

for(int i=1;i<5;i++)
{
    for(int j=5-i;1<=j;j--)
    {
        printf("*");
    }
    
    printf("\n");
}
    return 0;
}
0 votes
answered Aug 8, 2019 by Loki (1,600 points)
#include <stdio.h>

void main()
{
    int n,i=1,j=0;
    scanf("%d",&n);
    while(i++<n*2){
        j=0;
        if(i<n*2/2){
            while(j++<i)
                printf("*");
        }
        else{
            while(j++<n*2-i)
                printf("*");
        }
        printf("\n");
    }
}
works for any range Used while loop as required
0 votes
answered Aug 10, 2019 by yuvraj (300 points)
#include<stdio.h>
int main()
{
    int i,j,a;
    scanf("%d",&a);
    for(i=1;i<=a;i++)
    {
        for(j=1;j<=i;j++)
        {
        printf("* ");
        }
        printf("\n");
        }
    for(i=a;i>1;i--)
    {
        for(j=1;j<i;j++)
        {
            printf("* ");
        }
        printf("\n");
    }
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...