Tuesday, September 23, 2014

[LBC] Test day 1 - 2:

#include <stdio.h>
#include <stdlib.h>
#define MAX 12

int main(int argc, char *argv[]) {
float ftemp, months[12];
int i,j;
for (i = 0; i < 12; i++){
printf("Enter sales amount of month %d : ", i+1);
scanf("%f", &months[i]);
}
for (i = 11; i > 0; i--){
for (j = 11; j >= 12 - i; j--){
if (months[j] > months[j-1]){
ftemp = months[j-1];
months[j-1] = months[j];
months[j] = ftemp;
}
}
printf("After sort descending:\n");
for (i = 0; i < 12; i++){
printf("%.2f ", months[i]);
}
printf("\nTop 3 months with highest sales amount\n");
for (i = 0; i < 3; i++){
printf("%.2f \n", months[i]);
}
return 0;
}

No comments:

Post a Comment