Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [C++] ma che cosa ho sbagliato??

    ragazzi cosa ho sbagliato?



    #include <stdio.h>



    int main(void)
    {

    int contatore;
    int enne;
    int array[enne];


    printf("\nQuanti numeri interi vuoi che vengano ordinati in ordine crescente?\n"); /*quanto č capiente l'array?*/
    scanf("%d", &enne);

    for (contatore=0; contatore<enne; contatore++) /*loop per enne volte*/
    {
    printf("\nInserisci un valore intero da ordinare\n");
    scanf("%d",&array[contatore]);
    }

    /*OK, E ORA? IL LOOP FOR E' UNA CAVOLATA, MA PER METTERE IN ORDINE GLI*/
    /*ELEMENTI DELL'ARRAY NON SO PROPRIO COME FARE...SONO UN FALLITO!!!*/


    return(0);
    }
    There are two kinds of researchers:
    those that have implemented something and those that have not.
    The latter will tell you that there are 142 ways of doing things
    and that there isn't consensus on which is best.
    The former will simply tell you that 141 of them don't work.

  2. #2
    /* Si chiamano sort... e comunque la grandezza dell' array vā definita con un numero costante */

  3. #3
    prova questo
    codice:
    /* ordinamento per scambio: bubblesort */
    #include <stdio.h>
    #define MaxArray 5
    
    void Swap(int *, int *);
    
    void main()
    {
    	int Vet[MaxArray];
    	int unsigned i,j;
    
    	printf("Inserire i numeri da ordinare: \n");
    	for (i=0;i<MaxArray;i=i+1)
    	{
    		printf("%d  ",i);
    		scanf("%d/n",&Vet[i]);
    	}
    
    	printf("\nGli elementi dell'array sono:\n");
    	for (i=0;i<MaxArray;i++)
    		printf("%d  ",Vet[i]);
    	
    	/* ordinamento crescente */
    	for (i=0;i<MaxArray-1;i++)
    		for (j=i+1;j<MaxArray;j++)
    			if (Vet[i] > Vet[j])
    				Swap(&Vet[i],&Vet[j]);
    			
    	printf("\nGli elementi ordinati sono:\n");
    	i=0;	
    	while (i<MaxArray)
    	{
    		printf("%d  ",Vet[i]);
    		i++;
    	}
    	printf("\n");
    }
    void Swap(int *x, int *y)
    {
    	int scambio;
    
    	scambio=*y;
    	*y=*x;
    	*x=scambio;
    }

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.