0

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?

Edited by jaymayne

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by jaymayne
1

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.

Edited by Ancient Dragon

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.