Advertisement
Quzuri

labOceniane2Niewin

Nov 8th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {  
  6.     char characters[5][6]={
  7.                             {[5]='\0'},
  8.                             {[5]='\0'},
  9.                             {[5]='\0'},
  10.                             {[5]='\0'},
  11.                             {[5]='\0'},
  12.                           };
  13.     float probability, eps=10e-5;
  14.     int counterUpperCase=0, counterLowerCase=0;
  15.     printf("Podaj prawdopodobienstwo wylosowania małej litery(wartosc z przedzialu 0-1): ");
  16.     scanf("%f",&probability);
  17.     if (probability>1 || probability<0)
  18.     {
  19.         printf("Bledna wartosc prawdopodobienstwa!");
  20.         return 0;
  21.     }
  22.     for (int i=0;i<5;i++)
  23.     {
  24.         for (int j=0; j<5;j++)
  25.         {
  26.          float temp=(float)rand()/RAND_MAX;
  27.          if (temp<=probability)
  28.          {
  29.              int g=((int)rand()%26);
  30.              g+=97;
  31.              characters[i][j]=g;
  32.          }
  33.          else
  34.          {
  35.           characters[i][j]=((int)rand()%26)+65;
  36.          }
  37.         }
  38.        
  39.     }
  40.     printf("Zawartosc tablicy:\n");
  41.     for (int i=0;i<5;i++)
  42.         {
  43.             fputs(characters[i],stdout);
  44.             printf("\n");
  45.         }
  46.     for (int i=0;i<5;i++)
  47.     {
  48.         for (int j=0;j<5;j++)
  49.         {
  50.             if (characters[i][j]>91) counterLowerCase++;
  51.             else counterUpperCase++;
  52.         }
  53.     }
  54.     printf("Wielkie liczby wystapily %d/25 razy, a male %d/25 razy.", counterUpperCase, counterLowerCase);
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement