Facebook
From Rude Meerkat, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 139
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <stdlib.h>
  6.  
  7. void losowa( char rec[]);
  8. void nazwa (char plik[],char str[]);
  9.  
  10. int main() {
  11.     srand (time(NULL));
  12.     FILE *np1;
  13.     FILE *np2;
  14.     FILE *np3;
  15.     FILE *np4;
  16.     FILE *np5;
  17.  
  18.     char plik[20] = "";
  19.     char str1[20] = "P0001_";
  20.     char str2[20] = "P0002_";
  21.     char str3[20] = "P0003_";
  22.     char str4[20] = "P0004_";
  23.     char str5[20] = "P0005_";
  24.  
  25.  
  26.     printf("Witaj, podaj nazwe plikow\n");
  27.     scanf("%s", plik);
  28.  
  29.  
  30.     nazwa(plik,str1);
  31.     np1=fopen(str1, "w");
  32.     losowa(np1);
  33.     fclose(np1);
  34.  
  35.  
  36.      nazwa(plik,str2);
  37.      np2=fopen(str2, "w");
  38.      losowa(np2);
  39.      fclose(np2);
  40.  
  41.      nazwa(plik,str3);
  42.      np3=fopen(str3, "w");
  43.      losowa(np3);
  44.      fclose(np3);
  45.  
  46.  
  47.      nazwa(plik,str4);
  48.      np=fopen(str4, "w");
  49.      losowa(np4);
  50.      fclose(np4);
  51.  
  52.      nazwa(plik,str5);
  53.      np5=fopen(str5, "w");
  54.      losowa(np5);
  55.      fclose(np5);
  56.     return 0;
  57. }
  58. void nazwa (char plik[],char str[])
  59. {
  60.     strcat(str, plik);
  61.     strcat(str,".rec");
  62.    
  63.   return;
  64.  
  65. }
  66.  
  67. void losowa( char rec[]) {
  68.     float X=0.0;
  69.     float Y=0.0;
  70.     float RHO=0.0;
  71.     int LP=0;
  72.  
  73.     fprintf(rec, "LP \t X \t\t Y \t\t\t RHO");
  74.     while(LP < 50 )
  75.      {
  76.         LP=LP+1;
  77.         float X=  ( float) rand() /(float) RAND_MAX * 11.0;
  78.         float Y = 10 +(float) rand() /(float) RAND_MAX * 41.0;
  79.         float RHO= 2.7 +( float) rand() /(float) RAND_MAX *( 3.84 - 2.7);
  80.         fprintf (rec, "\n%d.\t%.5f\t\t%.5f\t\t%.3f\n",LP, X,Y, RHO );
  81.     }
  82.     return;
  83. }
  84.  
  85.