In: Computer Science
Submit a well-commented C program.
Create code.
That will build a random 8x8 2D array of small-case characters.
Demonstrate how it functions by printing out the result on your screen.
Add a function will print out a single line of the array. If the user enters a value between 0 and 7 to select to print out a single row of the original 2D array.
void printLine(char *,int); // This is the prototype declaration
void printLine(char myArr[][]) // This is the definition.
Note that L is the line to be printed.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void printLine(char [][8],int);
int main(){
int n;
printf("Enter value:");
scanf("%d",&n);
srand(time(0));
char myArray[8][8];
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
myArray[i][j]=(rand() % (122 - 97 + 1)) + 97;
}
}
printLine(myArray,n);
return 0;
}
void printLine(char myArray[][8],int n){
if(n>=0 && n<=7){
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
printf("%c",myArray[i][j]);
}
}printf("\n");
}
}
The function prototype must be same as function defination otherise it gives error
so the prototype is
void printLine(char [][8],int);
then only the function definition will works