Its an exam question that wants to modify code so that the following output is generated

1 2 3 4 5
2 3 4 5
3 4 5
4 5
5

This was the original code

#include<stdio.h>


void main()
{
    int i,j;

    for(i=1;i<5;i++)
    {

        for(j=1;j<=5;j++)
        {

            printf("%d",i);
        }

        printf("\n");
    }

}

and this is wat i have tried so far:

#include<stdio.h>
#include<conio.h>

void main()
{
    int i,j;

    for(i=1;i<=5;i++)
    {

        for(j=1;j<=5;j++)
        {

            printf("%d",i++);
        }

        printf("\n");
    }
    getch();

}

of course this jus prints one line: 12345
idk y im not able to figure this out plz help?

Recommended Answers

line 11: start the value of j = i counter instead of 1

line 14: print the value of j not i, and do not increment it on that line. It will be incremented on line 11. Finally, put a space in the format specifier so that there is a …

Jump to Post

All 2 Replies

line 11: start the value of j = i counter instead of 1

line 14: print the value of j not i, and do not increment it on that line. It will be incremented on line 11. Finally, put a space in the format specifier so that there is a space between the numbers printed on the screen.

lol thank you very much :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.