Помогите пожалуста

  • Автор темы ScorpionL
  • Дата начала
S

ScorpionL

Гость
#1
Помогите плиз исправить ошибки и переделать прогу из С в С++

C++:
#include <stdio.h> 
#include <stdlib.h> 
#include <time.h> 
#include <dos.h> 

void main(){ 
int n; 
int *z,*p,*d; 
FILE *f; 
struct dostime_t t,tnew; 
long delta; 
unsigned long k; 
int pm, dm, zpm; 
int i,m, w; 
_dos_gettime (&t); 
f=fopen("primer.in","rt"); fscanf(f,"%d",&n); 
z=(int*)malloc((n+2)*sizeof(int));
p=(int*)malloc((n+2)*sizeof(int)); 
d=(int*)malloc((n+2)*sizeof(int));
fclose(f); 
f=fopen("primer.out","wt"); 

for( i=l; i<=n;i++ ) { z[i] = p [i]; d [i] = -1; } 
d[l]=0; z[O]=z[n+1]=m=n+1; k=0; 
while( m!=1 ){ 
k++; fprintf (f,"\n%ld) ",k); 
for( i=1; i<=n; i++ )fprintf(f,"%d",z[i]); 
m=n; 
while ( z [p[m]+d[m] ]>m ){ d[m]=-d[m]; m—-; } 
pm=p [m]; dm=pm+d [m]; w=z [pm]; z [pm] =z [dm]; z [dm] =w; 
zpm=z[pm]; w=p[zpm]; p[zpm]=pm; p[m]=w; 
}
free(z); 
free(p); 
free(d); 
_dos_gettime(&tnew); 
delta=tnew.hour; delta-=t.hour; delta*=60; 
delta+=tnew.minute; delta-=t.minute; delta*=60; 
delta+=tnew.second; delta-=t.second; delta*=100; 
delta+=tnew.hsecond; delta-=t.hsecond; 
fprintf(f,"\nВремя счета %ld.%ld сек", 
(long)(delta/100), (long)(delta%100)); 
fclose(f);
}