|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
In the following program the inputs are taken randomly
#include<stdio.h> #include<stdlib.h> #include<conio.h> void main() { FILE *fp; int i,n,x,a[45],l=0,m,o,y,z,j; clrscr(); randomize(); fp=fopen("list1.txt","w"); if(fp==NULL) { puts("cannot open file"); exit(0); } n=rand()%14; for(i=1; i<=n; i++) { x=rand()%1000; a[i]=x; fprintf(fp,"%d\t",x); } fclose(fp); fp=fopen("list2.txt","w"); if(fp==NULL) { puts("cannot open file"); exit(0); } m=rand()%14; for(i=1; i<=m; i++) { y=rand()%1000; a[n+i]=y; fprintf(fp,"%d\t",y); } fclose(fp); fp=fopen("list3.txt","w"); if(fp==NULL) { puts("cannot open file"); exit(0); } o=rand()%14; for(i=1; i<=o; i++) { z=rand()%1000; a[n+m+i]=z; fprintf(fp,"%d\t",z); } fclose(fp); /* reading of first files starts here*/ fp=fopen("list1.txt","r"); if(fp==NULL) { puts("cannot open file"); exit(0); } printf("\nfirst list:----\n"); while(fscanf(fp,"%d",&x)!=EOF) printf("%d\t",x); fclose(fp); /*reading of second file starts here*/ fp=fopen("list2.txt","r"); if(fp==NULL) { puts("cannot open file"); exit(0); } printf("\nsecond list:----\n"); while(fscanf(fp,"%d",&y)!=EOF) printf("%d\t",y); fclose(fp); /*reading of third file starts here*/ fp=fopen("list3.txt","r"); if(fp==NULL) { puts("cannot open file"); exit(0); } printf("\nthird list:----\n"); while(fscanf(fp,"%d",&z)!=EOF) printf("%d\t",z); fclose(fp); printf("\n----------------------------------\n"); /*sorting all elements of array*/ printf("\nfinal sorted list-----------------\n"); for(i=1;i<=n+m+o;i++) { for(j=1;j<=n+m+o;j++) { if(a[j]>=a[j+1]) { int temp=a[j+1]; a[j+1]=a[j]; a[j]=temp; } } } /*storing values in final file*/ fp=fopen("list4.txt","w"); if(fp==NULL) { puts("cannot open file"); exit(0); } for(i=1; i<=m+n+o; i++) { x=a[i]; fprintf(fp,"%d\t",x); } fclose(fp); /*reading final file*/ fp=fopen("list4.txt","r"); if(fp==NULL) { puts("cannot open file"); exit(0); } while(fscanf(fp,"%d",&x)!=EOF) printf("%d\t",x); fclose(fp); getch(); } How do we modify this to take input from user that are 3 list of numbers one by one then we may get output( merged and sorted list) |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Best program for SQL database manipulation | Rhadamanthys | Database & Database Programming | 3 | 07-02-2007 03:32 PM |
| How do I Program another Program? ! | bosco | General Programming | 1 | 06-15-2007 12:15 PM |
| Need help w/ word count program (ASAP) | siren | C and C++ | 1 | 04-23-2007 09:14 AM |
| How to modify a program written in .NET 2.0? | jackyjack | C# Programming | 7 | 03-27-2007 01:26 PM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |