Sign in to follow this  
Cornel Iulian

[C] Triunghi de numere pentru un N definit

1 post in this topic

Cerinta: Sa se afiseze urmatorul triunghi de numere, pentru un N definit:

N

N N-1

N N-1 N-2

..............

N N-1 N-2 ... 3 2 1 

Rezolvare:

#include<stdio.h>
#include<stdlib.h>
  
int main(void)
{
	int n,i,j;
	printf("Introduceti o valoare lui N: ");
	if(scanf("%d",&n)!=1)
	{
		printf("Date eronate.");
		exit(1);
	}
	for(i=n;i>=1;i--)
	{
		for(j=n;j>=1;j--)
		{
			if(i==1 || i==j || i<j)
				printf("%d ",j);
		}
	printf("\n");
	}
	return 0;
}

 

Demo(pentru N=10):

triunghi.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this