I am working with microsoft visual studio 2012 and trying to make a bubble sort. Here is my code:
#include "stdafx.h"
#include "String.h"
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int array[100], n, c, d, swap;
printf("enter numbers of elements\n");
scanf_s("%d",&n);
printf("enter %d integers\n", n);
for (c = 0; c < n; c++){
scanf_s("%d", array);
}
for (c = 0; c < (n - 1); c++)
{
for (d = 0; d < n - c - 1; d++)
{
if (array[d]>array[d + 1]){
swap = array[d];
array[d] = array[d + 1];
array[d + 1] = swap;
}
}
}
printf("sorted list in ascending order:\n");
for (c = 0; c < n; c++){
printf("%d\n", &array[c]);
}
getchar();
return 0;
}
First of all I can't make console stay for a key entry. getchar()
seems like not working but i don't have any error. Plus when I see console for a second, I can say that numbers are listed like "-310892". I don't know why.