Este código nos sirve para ordenar números de mayor a menor, los números que se ordenan son los ingresados por el usuario.
El código es el siguiente:
//Ordenamiento de números con vectores
#include <stdio.h> #include <conio.h>
void burbuja(int a[],int n); int main(void) { int const n=4; int i,a[n]; for(i=0;i<n;i++) { printf("Ingrese el %d numero=",i+1); scanf("%d",&a[i]); } burbuja(a,n); printf("\nNumeros ordenados:\n"); for(i=0;i<n;i++) printf("%d digito=%d\n",i+1,a[i]); getch(); return 0; } void burbuja(int a[],int n) { int i,j,aux; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(a[i]<a[j]) { aux=a[i]; a[i]=a[j]; a[j]=aux; } }
En este código utilizamos un método llamado ordenamiento de burbuja, se trata de un algoritmo que cambia la posición de los valores para ordenarlos ya sea de mayor a menor o de menor a mayor. Es muy utilizado para programas que colectan muchos datos y estos deben ordenarse.
En el código se crea una función llamada burbuja que contiene las variables enteras a y b, en la función main, el programa pide los datos, en este caso 4 pero se puede modificar este valor editando la variable const.
Con ciclos for se hace el ordenamiento respectivo para después imprimir el resultado en pantalla.
Si requieres algún programa en específico, no dudes en contactarnos aquí para una cotización.
Mira calcular rfc bien hecho segun yo 🙂 en c-free
#include
#include
#include
#include
int main (void)
{
char nom[15], nom2[15], ape[15], ape2[15], f[10]={0},rfc[11], txt;
int x=0;
printf(«\n\t Ingrese el nombre:\t»);
while((txt=getch())!=13)
{
if (isalpha(txt))
{
nom[x]=txt;
printf(«%c» , nom[x]);
x=x+1;
}
if(txt==8)
{
if(x>0)
{
printf(«\b \b»);
x=x-1;
nom[x]=»;
}
}
}
x=0;
printf(«\n\tIngrese segundo nombre:\t»);
while((txt=getch())!=13)
{
if(isalpha(txt))
{
nom2[x]=txt;
printf(«%c», nom2[x]);
x=x+1;
}
if(txt==8)
{
if(x>0)
{
printf(«\b \b»);
x=x-1;
nom2[x]=»;
}
}
}
x=0;
printf(«\n\t Ingrese apellido parterno:\t»);
while((txt=getch()) !=13)
{
if(isalpha(txt))
{
ape[x]=txt;
printf(«%c», ape[x]);
x=x+1;
}
if(txt==8)
{
if(x>0)
{
printf(«\b \b»);
x=x-1;
ape[x]=»;
}
}
}
x=0;
printf(«\n\t Ingrese apellido materno:\t»);
while((txt=getch()) !=13)
{
if(isalpha(txt))
{
ape2[x]=txt;
printf(«%c», ape2[x]);
x=x+1;
}
if(txt==8)
{
if(x>0)
{
printf(«\b \b»);
x=x-1;
ape2[x]=»;
}
}
}
x=0;
printf(«\n\tIngrese la fecha de su nacimiento Dia/Mes/ano:\t»);
while(x!=10)
{
if(isdigit(txt=getch()))
{
f[x]=txt;
if(x==0)
{
if(txt>=52)
{
printf(«\b \b»);
x=x-1;
f[x]=»;
}
}
if(x==1)
{
if(f[0]==51)
{
if(txt>=50)
{
printf(«\b \b»);
x=x-1;
}
}
}
if(x==3)//mes 1er dijit//
{
if(txt>=50)
{
printf(«\b \b»);
x=x-1;
}
}
if(x==4)//mes 2do dijit//
{
if(f[3]==49)
{
if(txt>=51)
{
printf(«\b \b»);
x=x-1;
}
}
}
if(f[3]==48 && f[4]==50) //nuevo mes de febrero
{
if(f[0]==51 || f[0]==50 && f[1]==57)
{
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
}
}
if(f[3]==48 && f[4]==52)//mes de abril//
{
if(f[0]==51 && f[1]==49)
{
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
}
}
if(f[3]==48 && f[4]==54)//mes de junio//
{
if(f[0]==51 && f[1]==49)
{
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
}
}
if(f[3]==48 && f[4]==57)//mes de septiembre//
{
if(f[0]==51 && f[1]==49)
{
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
printf(«\b \b»);
x=x-1;
}
}
if(x==6) //años local 1//
{
if(txt>=51)
{
printf(«\b \b»);
x=x-1;
}
if(txt==48)
{
printf(«\b \b»);
x=x-1;
}
}
if(x==7)//años local 2 //
{
if(f[6]==49)
{
if(txt=49)
{
printf(«\b \b»);
x=x-1;
}
}
}
if(x==8) //años local 3//
{
if(f[6]==50)
{
if(txt>=50)
{
printf(«\b \b»);
x=x-1;
}
}
}
if(x==9) //años local 4//
{
if(f[6]==50)
{
if(txt>=52)
{
printf(«\b \b»);
x=x-1;
}
}
if(f[5]==49)
{
if(txt>=58)
printf(«\b \b»);
x=x-1;
}
}
printf(«%c», f[x]);
if(x==1 || x==4)
{
f[2]=’/’;
f[5]=’/’;
x=x+1;
printf(«%c», f[x]);
}
x=x+1;
}
if(txt==8)
{
if(x>0)
{
printf(«\b \b»);
x=x-1;
f[x]=»;
}
}
}
x=1;
while(x!=10)
{
if(ape[x]==’a’||ape[x]==’e’||ape[x]==’i’||ape[x]==’o’||ape[x]==’u’||ape[x]==’A’||ape[x]==’E’||ape[x]==’I’||ape[x]==’O’||ape[x]==’U’)
{
rfc[0]=ape[0];
rfc[1]=ape[x];
rfc[2]=ape2[0];
rfc[3]=nom[0];
rfc[4]=’-‘;
rfc[5]=f[8];
rfc[6]=f[9];
rfc[7]=f[3];
rfc[8]=f[4];
rfc[9]=f[0];
rfc[10]=f[1];
printf(«\n\tRFC: %s\t\n», rfc);
x=10;
}
else
{
x=x+1;
}
}
}
// By Low Light //