Hey guys i need help with a program
The first function outputs the n elements stored in the array, and the second function sorted the array using the basic bubble sort.
i'm unsure of how to use arrays properly so i don't know exactly how to print and input both size and numbers in an array
i'm support to sort the array
i think at least some parts of the code may be right but i'm sure what i'm doing right or wrong as i'm not sure about how to use arrays properly
any help would be grateful thanks
Code:
#include <stdlib.h>#include <stdio.h>
#include <string.h>
void intSwap(int *x, int *y);
int getIntArray(int a[], int nmax, int sentinel);
void printArray(int a[], int n);
int main()
{
int i, j, temp, pass, size, array;
scanf("%d", &array);
/*print array*/
/*sorts the array*/
/*sorts printed array*/
int x[100];
int hmny;
array = getIntArray(x, 100, 0);
printf("The array was: \n");
printArray(x,array);
printf("after reverse it is:\n");
printArray(x,array);
}
/*void intSwap(int *x, int *y)
/* It swaps the content of x and y */
/*
{
int temp = *x;
*x = *y;
*y = temp;
}
void bubbleSort(int a[], int size)
{
int pass, j, size, temp, end;
pass =1;
while (pass <= size-1)
{
j=0;
end = size -1 - pass;
while (j <= end)
{
if(a[j] > a[j+1])
{temp = a[j]; a[j] = a[j+1]; a[j+1] = temp}
j = j+1;
}
pass = pass + 1;
}
*/
/*
void PrintArray(int a[], int n){
int i;
for (i=0; i<n; ){
printf("\t%d ", a[i++]);
if (i%5==0)
printf("\n");
}
printf("\n");
}
*/
/* It reads up to nmax integers and stores then in a; sentinel
* terminates input. */
int getArray(int a[], int nmax, int sentinel)
return n;
}
/*{
int n = 0;
int temp;
while(temp<sentinel)
printf("Enter integer [%d to terminate] : ", sentinel);
scanf("%d", &temp);
if (temp==sentinel) break;
if (n==nmax)
printf("array is full\n");
else
a[n++] = temp;
}while (1);
*/