Your C program will do the following :
Must use at least 2 function prototypes & definitions . You can also use repetitions , control structures . You re not allowed any type of global arrays, or global variables. You are only allowed to use 2 dimensional arrays.
1. In your main program, create a array of size 7 X 7.
2. Create a function that accepts the empty array. The function will initiate the to zero. Then, the function will populate the array with random number of 0’s and 1’s only. Use a random number generator to generate the 0’s and 1’s.
3. From main Display the 2 d array.
4. From main , pass the populated array to another function.
The purpose of the to do the following : a. Asks for two integer indices i and j (less or equal to n) or -1 .
b. Return the number of nonzero elements of the array that are adjacent to the i-th and j-th element of the array
c. repeat steps a and b until -1 is entered to exit the function.
5. Repeat steps 2 – 4 until the user terminates the program by entering N/n .
You need to use the following libraries in order to generate the random number stdlib , stdio, and time libraries . you also need the srand(time(0)) in order to get a different random number every time you generate a number.
Finally , you need the command that generates the number and stores it in a variable .
• i-th row and j-column must be integers between 1 and 7 or -1 to terminate. Otherwise an error should be displayed.
• The program must be running until the user decides to terminated it by entering n.
Here is the answer for your question in C Programming Language.
Kindly upvote if you find the answer helpful.
####################################################################
CODE :
#include<stdio.h>
void main(){ printf("Enter i and j(1 to 7) indices
values(-1 to stop): "); |
#######################################################
SCREENSHOTS :
Please see the screenshots of the code below for the indentations of the code.
####################################################################
OUTPUT :
Any doubts regarding this can be explained with pleasure :)
Get Answers For Free
Most questions answered within 1 hours.