ProgIng - Programación en Ingeniería
Loading...
Searching...
No Matches
Ejemplo043.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <time.h>
3#include <stdlib.h>
4#include <string.h>
5
6#define N 50
7
8int main(int argc, char *argv[])
9{
10 int i, n;
11 double x;
12 FILE *fp;
13 char filename[N];
14 do{
15 printf("Ingrese el valor de n: ");
16 scanf("%d", &n);
17 }while(n<1);
18 if(argc==2)
19 strcpy(filename, argv[1]);
20 else
21 strcpy(filename, "Prueba.txt");
22 fp = fopen(filename, "wt");
23 if(fp==NULL)
24 return 1;
25 srand(time(NULL));
26 fprintf(fp, "%d\n", n);
27 for(i=0; i<n; i++)
28 {
29 x = (1.0*rand())/RAND_MAX;
30 fprintf(fp, "%d\t%lf\n", i+1, x);
31 printf("x[%d] = %lf\n", i+1, x);
32 }
33 fclose(fp);
34 return 0;
35}
#define N
int main(void)
Definition Ejemplo_035.c:15