Advertisement
Mary_99

probability

Dec 29th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5.  
  6. int main(int argc, char *argv[]) {
  7.  
  8.     int N, M;
  9.     int i, j ,probability;
  10.     char a;
  11.     char b;
  12.    
  13.     printf("Enter the number of rows: \n");
  14.     scanf(" %d", &N);
  15.     printf("Enter the number of columns: \n");
  16.     scanf(" %d", &M);
  17.    
  18.     printf("\nEnter first character");
  19.     scanf(" %c", &a);
  20.     printf("\nEnter second characters");
  21.     scanf(" %c", &b);
  22.  
  23.     while(isdigit(a) || isdigit(b))//check if sine is a digit
  24.     {
  25.         printf("\nEnter two characters");
  26.         scanf(" %c %c", &a, &b);
  27.     }
  28.    
  29.     for (i= 0; i<N; i++)
  30.     {
  31.         for(j=0; j<M; j++)
  32.         {
  33.             probability=rand()%10; //probability about 1 of 10
  34.             if(probability==1) //probilityy = 1
  35.             {
  36.                 printf("%c", a);
  37.             }
  38.             else
  39.                 {
  40.                     printf("%c", b);   
  41.                 }
  42.                
  43.         }
  44.         printf("\n");
  45.     }
  46.    
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement