Code:
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include "c:\Dev-C++\Graphics\winbgim.h"
int main() {
void sort(float *, int);
int j;
int cnt = 0;
const int num = 10;
char tempstr[20];
char highstr[20];
float x[num] = {2.3, 5.66, 1.22, 5, 6.777, 3.2, 5.13, 2.862, 1, 5.01};
float curhigh = 0.0;
int driver;
int mode;
driver = DETECT;
mode = 0;
initgraph(&driver, &mode, "");
setcolor(BLUE);
settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
outtextxy(12, 25, "Original");
for (j = 0; j < num; j++) {
cnt += 20;
sprintf(tempstr, "%.2f", x[j]);
outtextxy(12, 30 + cnt, tempstr);
if (x[j] > curhigh) {
curhigh = x[j];
}
}
setcolor(RED);
sprintf(highstr, "%.2f", curhigh);
outtextxy(20, 300, "Highest Value");
outtextxy(20, 320, highstr);
float temp[num];
temp = x;
sort(x, num);
cnt = 0;
for (j = 0; j < num; j++) {
cnt += 20;
sprintf(tempstr, "%.2f", temp[j]);
outtextxy(400, 30 + cnt, tempstr);
}
getch();
return 0;
}
void sort(float *ptr, int n) {
int j, k;
int cnt = 0;
char tempstr[20];
float temp;
for (j = 0; j < n - 1; j++) {
for (k = j + 1; k < n; k++) {
if (ptr[j] > ptr[k]) {
temp = ptr[j];
ptr[j] = ptr[k];
ptr[k] = temp;
}
}
}
setcolor(RED);
settextstyle(4, HORIZ_DIR, 2);
outtextxy(310, 25, "Sorted");
for (j = 0; j < n; j++) {
cnt += 20;
sprintf(tempstr, "%.2f", ptr[j]);
outtextxy(250, 30 + cnt, tempstr);
}
}
If anyone tries to run this it must have the following in compiler options: "-mwindows <path of the winbgim.cpp file>"