TURBO C ++ HELP! INTERATIVE STATEMENT

Im a beginner so please help me.

USING FOR LOOP:

write a program that will display the following pattern, given the value of n.
example: of n=4 output:
1234
123
12
1

ok im sorry. im still a noob.

ohk i tried this code but wrong out.

#include <stdio.h>
#include<conio.h>
#define p printf
#define s scanf

void main()
{
int a;
clrscr();
p("\nEnter a number: "); s("%d",&a);
for(int x=1; x<=a; x++)
{

for(int y=1; y<=a; y--);
{
p("\n");
}
}
getche();
}

Don't write obfuscated code by defining standard C functions to have a different name. That's a very very bad coding style to do that, which might get you lower marks by your instructor.

Don't write obfuscated code by defining standard C functions to have a different name. That's a very very bad coding style to do that, which might get you lower marks by your instructor.

ok. but any help please?

Hello xshinichix, if it does not hurt you, your code is in complete out of order state.

It might be compiling OK, but there is some logical problem in it.

Let me repair it one by one.

1. Firstly, put your code in code tag. It is very annoying to read a unformatted code.
2. Never, use two statements in same line as p ("\nEnter a number: "); s("%d",&a); is there in this code. It is considered to be bad progamming/ code.
3. Never use preprocessor directive unnecessary. It creates more confusion in debugging to anyone who reviews
that code at a later time ( including you ).
4. Try to follow the C++ specification. Not use the flexibility provided by C++ Compiler Design. Always start indexing at 0 in both C++ and C.
5. May be this code will help you to pinpoint the logical error.

.
.


for( x = 0; x < a; x++ )
{
	for (  y = 0; y < ( a - x ); y++ )
	{
		printf("%d", y + 1 );
	}

	printf("\n");
}

.
.
.

6. use proper formatting in your code.
7. If it is compiled using C++ compiler, then everything is OK, otherwise if it is for C Compiler,
never use declaration statements in middle of the program as int i or something like that.

May this help you.
-Manoj

Edited 6 Years Ago by manojwali: n/a

Hello xshinichix, if it does not hurt you, your code is in complete out of order state.

It might be compiling OK, but there is some logical problem in it.

Let me repair it one by one.

1. Firstly, put your code in code tag. It is very annoying to read a unformatted code.
2. Never, use two statements in same line as p ("\nEnter a number: "); s("%d",&a); is there in this code. It is considered to be bad progamming/ code.
3. Never use preprocessor directive unnecessary. It creates more confusion in debugging to anyone who reviews
that code at a later time ( including you ).
4. Try to follow the C++ specification. Not use the flexibility provided by C++ Compiler Design. Always start indexing at 0 in both C++ and C.
5. May be this code will help you to pinpoint the logical error.

.
.


for( x = 0; x < a; x++ )
{
	for (  y = 0; y < ( a - x ); y++ )
	{
		printf("%d", y + 1 );
	}

	printf("\n");
}

.
.
.

6. use proper formatting in your code.
7. If it is compiled using C++ compiler, then everything is OK, otherwise if it is for C Compiler,
never use declaration statements in middle of the program as int i or something like that.

May this help you.
-Manoj

thank you sir. here's my final output:

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

void main()
{
int a,x,y;
clrscr();
printf("Enter a number: \n");
scanf("%d",&a);
 for(x=0;x<a;x++)
 {
	for(y=0;y<(a-x);y++)
	{
	  printf("%d",y+1);
	}
	printf("\n");
 }
getche();
}
This question has already been answered. Start a new discussion instead.