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.

I need the optimised code in c language of the given pattern below.

–2 votes
asked Aug 26, 2018 by anonymous
3
44
555
6666
555
44
3

2 Answers

0 votes
answered Aug 26, 2018 by Jay
#include <stdio.h>

int main()
{
    int a,i;
     for(a=3;a<=6;a++)
    {
        for (i=1;i<=a-2;i++){
            printf("%d",a);
        }
        printf("\n");
    }
    for(a=5;a>=3;a--)
    {
        for (i=1;i<=a-2;i++){
            printf("%d",a);
        }
        printf("\n");
    }

    return 0;
}
commented Aug 27, 2018 by anonymous
Thanks a lot, jay for taking an interest in my problem.
Will you please make a change in my code to get the same output.

#include<stdio.h>
int main()
{
    int i,j,k=i,x=3;
    
    for(i=1;i<=7;i++){
        i<=4 ? k++ : k--;
        for(j=1;j<=4;j++){
            if(j<=k)
                printf("%d",x);
                else
                print(" ");
        }
            printf("\n");
    }
}
0 votes
answered Aug 27, 2018 by BhanuPrakash
#include <stdio.h>

int main(void) {

    int i,j,k=3,t=5,g=3;

    for(i=0;i<4;i++)

    {

        for(j=0;j<=i;j++)

        {

            printf("%d",k);

        }

        printf("\n");

        k++;

    }

    for(i=0;i<3;i++)

    {

        for(j=0;j<g;j++)

        {

            printf("%d",t);

        }

        printf("\n");

        t--;

        g--;

    }

// your code goes here

return 0;

}
commented Aug 27, 2018 by anonymous
Thanks a lot, Bhanu Prakash for taking an interest in my problem.

Will you please make a change in my code to get the same output.

#include<stdio.h>
int main()
{
    int i,j,k=i,x=3;
    
    for(i=1;i<=7;i++){
        i<=4 ? k++ : k--;
        for(j=1;j<=4;j++){
            if(j<=k)
                printf("%d",x);
                else
                print(" ");
        }
            printf("\n");
    }
}
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.
...