Sign in to follow this  
Cornel Iulian

[C] Ordonarea in ordine crescatoare a 3 numere intregi in C

1 post in this topic

Cerinta: Sa se creeze un program care ordoneaza in ordine crescatoare 3 numere intregi introduse de la tastatura.

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int a,b,c,aux;
	printf("Introduceti numerele:\n");
	if(scanf("%d%d%d",&a,&b,&c)!=3)
	{
		printf("Date eronate");
		exit(1);
	}
	if(a>b)
	{
		aux=a;
		a=b;
		b=aux;
	}
	if(b>c)
	{
		aux=b;
		b=c;
		c=aux;
	}
	if(a>b)
	{
		aux=a;
		a=b;
		b=aux;
	}
	printf("Numerele puse in ordine crescatoare:\na=%d\nb=%d\nc=%d",a,b,c);
	
	return 0;
}

 

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