Click here to Skip to main content
16,011,358 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
#include <stdio.h>
void main()
{
int i,j,rows;
scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(j=1;j<=rows;j++)
{
printf("%d",j);
}
printf("\n");
}
}

What I have tried:

I am getting expected ouput:1,23,456,78910
when input:4,your program output:1,12,123,1234
Posted
Updated 15-Dec-20 3:45am
Comments
Richard Deeming 15-Dec-20 9:41am    
REPOST
You have already posted this homework assignment and accepted a solution:
Is there any error in this program[^]

Quote:
I am getting expected ouput:1,23,456,78910

No you're not. When running this program I get 4 rows of 1234 when input 4.
Quote:
when input:4,your program output:1,12,123,1234

I'm guessing that this is what your assignment is supposed to achieve. Since that's not what's going on I suggest you look into how to use the debugger on your system and find out why that's not happening.

Other notes:
There's no prompt for input, so its not clear when the program is ready for input
main() always returns an int, even if you don't say return 0; at the end, the compiler will add it for you, and you should always declare main accordingly.
 
Share this answer
 
Quote:
Is there any error in this program

Short answer: Yes.
Quote:
I am getting expected ouput:1,23,456,78910

Try to make correct sentences. Is it what you want or what you actually get?
Quote:
when input:4,your program output:1,12,123,1234

Your program do not give this output, neither previous one, a simple run should have show it to you.
Your code output is rather
1234
1234
1234
1234

which is none of the outputs
 
Share this answer
 
Comments
Group 15005118 15-Dec-20 11:18am    
For me in the question output is given as 1,23,456,78910

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900