I am trying to produce a random matrix filled only with 1's and 0's but am struggling. I woudl appreciate anyones advice!
This is my code so far:
insertEmmaCode:#include <stdio.h> #include <stdlib.h> main(){ int a[10][10]={0}; int n,p, noofelements, randomno, rowpos, colpos; int i,j,k; srand(k); printf("Enter the seed: "); scanf("%d", &k); printf("Enter the number of rows: "); scanf("%d", &p); printf("Enter the number columns: "); scanf("%d", &n); noofelements=n*p; for (i=1; i<=noofelements; i++) { rowpos=rand()%n; colpos=rand()%p; a[rowpos][colpos]=i; } for (i=0; i<p; i++) { for (j=0; j<n; j++) printf("%d\t", a[i][j]); printf("\n"); } }



LinkBack URL
About LinkBacks


