Write a program for following output using while loop

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

12 Answers

0 votes
answered Jul 31 by (300 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 by anonymous 1 flag
Outer loop runs 11 times. There are only 9 lines in output.
0 votes
answered Jul 31 by (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 by kuelf
edited Aug 8
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 by (1,600 points)
what sort of answer is this
commented Aug 8 by anonymous
Edited..............
0 votes
answered Aug 2 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 by (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 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 by (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 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 by (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 by (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.
...