#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. :(

Dani AI

Generated

This program prints a right-angled numeric triangle: each outer-loop iteration produces one row, and the inner loop prints a descending sequence that gets shorter each row. For an input of 5 the rows printed are 54321, 5432, 543, 54, 5 — the first row starts at a, the last row starts at 1.

Step-by-step: the outer loop (x = 1 .. a) controls the row number. For each x the inner loop initializes y = a - x + 1, then repeats while y >= 1, doing y-- each time. That initialization makes the first row start at a (when x == 1, y == a) and the last row start at 1 (when x == a, y == 1). The statement y-- simply decrements the numeric value; it does not change character case (so ’s “uppercase to the lowercase” remark is a misphrasing).

A few practical notes and small fixes:

  • void main() and conio.h/getch() are nonstandard in C++; prefer int main() and avoid platform-specific headers.
  • Printing without separators joins digits (so 10 becomes "10" next to 9 → "109..."). Add a space if you want numbers separated.
  • Validate input (check scanf/cin) and handle a <= 0 explicitly.
  • For clarity and portability use modern C++ iostreams.

Example corrected main loop (C++ style):

#include <iostream>

int main() {
    int a;
    std::cout << "Enter number of inputs: ";
    if (!(std::cin >> a) || a <= 0) return 0;
    for (int x = 1; x <= a; ++x) {
        for (int y = a - x + 1; y >= 1; --y)
            std::cout << y;
        std::cout << '\n';
    }
    return 0;
}

Edge cases to watch: very large a (performance/formatting), negative or zero input (no output), and whether you want spaces between numbers. This clarifies the loop math so the pattern becomes predictable.

pleas the full code

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. :(

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 ????

Be a part of the DaniWeb community

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