English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write a interactive program that reads three(3) lists of numbers, which are stored in three seprate files, and creates one(1) sorted list. Each file should contain not more than 15 numbers. First you need to create a program that randomly chooses a size(<=15 numbers) for list1. Repeat this procedure to select the other two lists(list2 and list3) and stores them in the corresponding files(file2 and file3) for sorting and merging them into one.

file1(list 1) 32 12 5 990 1
file2(list 2) 2000 3
file3(list 3) 30 6

output in a separate file:
1 3 5 6 12 30 32 990 2000

2007-03-25 18:09:56 · 4 answers · asked by tricky 2 in Computers & Internet Programming & Design

......in c language....

2007-03-25 18:17:27 · update #1

4 answers

#include"stdio.h"
void main(){
FILE *fp1,*fp2,*fp3,fp4;
char ch1;
int temp_arr[50];
int i=0;
int limit;

fp1=fopen("file1","w");fp2=fopen("file2","w");fp3=fopen("file3","w");

printf("\nEnter nums for file1: ");
for(i=0;i<15;i++){ scanf("%d",&temp_arr[i]); ch1=(char)temp_arr[i]; fputc(ch1,fp1); fputc('\n');}

printf("\nEnter nums for file2: ");
for(i=0;i<15;i++){ scanf("%d",&temp_arr[i]); ch1=(char)temp_arr[i]; fputc(ch1,fp2);fputc('\n');}

printf("\nEnter nums for file3: ");
for(i=0;i<15;i++){ scanf("%d",&temp_arr[i]); ch1=(char)temp_arr[i]; fputc(ch1,fp3);fputc('\n');}

fclose(fp1);fclose(fp2);fclose(fp3);

fp1=fopen("file1","r");fp2=fopen("file2","r");fp3=fopen("file3","r");

fp4=fopen("result","w");

while((ch1=fgetc(fp1))!=EOF){ temp_arr[i++]=(int)ch1;}
while((ch1=fgetc(fp2))!=EOF){ temp_arr[i++]=(int)ch1;}
while((ch1=fgetc(fp3))!=EOF){ temp_arr[i++]=(int)ch1;}

//Use bubble or selection sort and sort the numbers if u requrire it i shall send u

limit = i;
i=0;
while(limit>0){ fwrite(fp4,"%d",temp_arr[i++]); limit-=1; }
}

2007-03-26 18:15:07 · answer #1 · answered by Anonymous · 0 0

First read in the three files and store them in an array.

Then sort them, the easiest way is to find the smallest number and switch its position with the number in the first spot of the array. Then find then next smallest number and switch its position with the number in the second spot of the array. Do that all they way through.

Then output the array to the other file.

It all depends on what language you are using for what the code would be.

2007-03-26 01:17:24 · answer #2 · answered by Logan K 1 · 0 0

Sounds like someone doesn't want to have to break down and actually learn to do their own homework... What language is this supposed to be in?

2007-03-26 01:14:58 · answer #3 · answered by Rex M 6 · 0 1

it shal work mate go slow

(UK)

2007-03-26 01:17:10 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers