Code:
#include <stdio.h>
#include <conio.h>
void sort(int *, int); /*taulukko järjestely funktio esittely*/
int main()
{
int lkm=0;
int i=0; //arrays start at zero in C
int taulukko[127]={0};
int summa=0;
do
{
printf("Anna luku %d.", i);
scanf("%d", &taulukko[i]);
lkm++;
i++;
}while(taulukko[i-1]>0);
lkm--;
for(i=0; i<lkm; i++)
{
summa+=taulukko[i];
}
sort(taulukko, lkm);
//you'll want to print or do other work with the sorted array, here
printf("\nlukujen keskiarvo on %d ja pienin syottama luku on %d", summa/lkm, taulukko[1]);
getch();
return 0;
}
void sort(int * taulukko, int lkm) /*taulukon järjestely funktio*/
{
int g,r,c;
for ( r=0; r < lkm-1; r++) //remember to minus 1, here
{
for ( g=r+1;g<lkm; g++)
{
if ( taulukko[r] < taulukko[g] ) // descending order
{
c=taulukko[r]; // these 3 statements swap values
taulukko[r] = taulukko[g]; // in the 2 cells being compared
taulukko[g] = c;
}
}
}
}
That should give you a few suggestions for progress.
Edit: I'm not sure this is working right since I can't understand your program's message.
If you want the smallest number, just add:
Code:
printf("\nSmallest integer was: %d\n", taulukko[lkm]); //lkm - 1 to skip the zero
//to see all the sorted numbers
for(i = 0; i < lkm; i++)
printf("\n %d", taulukko[i]); //<= lkm to see the zero