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

void main()
{
int a;

printf("\nEnter number of inputs: ");
scanf("%d", &a);

  for( int x=1; x<=a; x++ ) 
{
	for( int y=a-x+1; y>=1; y--) 
	{
	printf("%d",y);
	}
  printf("\n");

}
getch();
}

im still a noob. i know the output of this one. but i cant seem really understand the logic. i forgot what our instructor told us. :(

Edited 6 Years Ago by xshinichix: n/a

pleas the full code

ok sir here it is:

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

void main()
{
int a;

printf("\nEnter number of inputs: ");
scanf("%d", &a);

  for( int x=1; x<=a; x++ ) 
{
	for( int y=a-x+1; y>=1; y--) 
	{
	printf("%d",y);
	}
  printf("\n");

}
getch();
}

ok now i can explain it for you:

line 6 assign integer a.

line 8 saying Enter number of inputs, this is meaning that's you enter numbers.

line 9 makeing the input of a so when line 8 execute you can assign the value you need to a.

here we start the lines i think you need to know

line 11 saying the following : make a new integer called x and assign 1 for it, then it say x is less than or equal to a, so he makeing all the previous to make a loop that ends when x = a, then he just say x++ to make it count till it get to a value.

clear till now ????

in line 13 he saying a new nested for loop and saying the following

made a new integer called y and assign it to be y = a-x+1, and assign y to be less than or equal one, and make y-- to minus by one.

so because he in the first made x=1, and x++ untill it be the same like a.

he now made y-- to get it from the uppercase to the lowercase .

and in line 15 he print the integer y to appear like what we said from upper
to lower.

any thing unclearlly ????

ok now i can explain it for you:

line 6 assign integer a.

line 8 saying Enter number of inputs, this is meaning that's you enter numbers.

line 9 makeing the input of a so when line 8 execute you can assign the value you need to a.

here we start the lines i think you need to know

line 11 saying the following : make a new integer called x and assign 1 for it, then it say x is less than or equal to a, so he makeing all the previous to make a loop that ends when x = a, then he just say x++ to make it count till it get to a value.

clear till now ????

in line 13 he saying a new nested for loop and saying the following

made a new integer called y and assign it to be y = a-x+1, and assign y to be less than or equal one, and make y-- to minus by one.

so because he in the first made x=1, and x++ untill it be the same like a.

he now made y-- to get it from the uppercase to the lowercase .

and in line 15 he print the integer y to appear like what we said from upper
to lower.

any thing unclearlly ????

so sir do you mean in line 11, if I put number 5, sot it means 1<=5? and so it will print 5, so the increment will change each time the loop is reapeted but how about line 13? i mean what if I input number 5. im confused about the nested loop. :(

Edited 6 Years Ago by xshinichix: spelling

yea that's what i mean in the line 11 he is makeing 5 loops ok

so he didn't appear them till now he is appearing the nested loop first

so he just appearing 54321 first line
5432 second line
543 third line
54 forth line
5 fifth and last line

he is minus by one
he is makeing y--

clear ????

This article has been dead for over six months. Start a new discussion instead.