include stdio include conio include math include stdlib include ctype

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <dos.h>
#include <bios.h>
int myTime(void) {
struct time t;
window(45,1,80,1);
textcolor(WHITE);
cprintf("Press any key for exit");
window(70,1,80,1);
textcolor(WHITE);
textbackground(RED);
while(!bioskey(1)) {
clrscr();
gettime(&t);
cprintf(" %2d:%02d:%02d",
t.ti_hour,t.ti_min,t.ti_sec);
delay(500);
}
return 0;
}
int main (char*argv[])
{
struct text_info ti;
char buffer [4096];
gettextinfo(&ti);
gettext (1,1,80,25,buffer);
clrscr();
int x = atoi(argv [1]);
int s=0;
int d;
double arr[20];
for(d=0; d<=20; d = random(30))
{
s=s+(3+x)+(pow(x,3)*d);
arr[d]=s;
}
printf("Before sorting \n\n");
int i;
for (i=0;i<20; i++)
{
printf("%f \n",arr[i]);
}
int j,imin;
double min;
for (i=1; i<20; i++)
{
min=arr[i];
for (j=i; j<20; j++)
if (arr[j]<min)
{
min=arr[j];
imin=j;
}
arr[imin]=arr[i];
arr[i]=min;
}
printf("After sorting \n\n");
for (i=0;i<20; i++)
{
printf("%f \n",arr[i]);
}
//ADDED
FILE *f;
if((f=fopen("D:/file.txt","wt"))==NULL)
{
fprintf(stderr,"Can't open output file\n");
return(1);
}
for(i=0;i<20;i++) fprintf(f,"%f \n",arr[i]);
//ADDED
myTime();
fflush(stdin);
textmode(ti.currmode);
textattr(ti.attribute);
puttext(1,1,80,25,buffer);
gotoxy(ti.curx,ti.cury);
getch();
return 0;
}