Question

C Programming.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Explanation:

This program will give us the random genarated values in the out put. Please find the attached out put screen shot for one of the random generated out put pattern.

Program:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define ROWSOBJ 10
#define COLSOBJ 10
int main (void) {

int iObj, jObj, kObj, directionObj;
char boardObj[ROWSOBJ][COLSOBJ];
const char lettersObj[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

srand ((unsigned) time(NULL));

for (iObj = 0; iObj < ROWSOBJ; iObj++)
for (jObj = 0; jObj < COLSOBJ; jObj++)
boardObj[iObj][jObj] = '.';

iObj = 0;
jObj = 0;
kObj = 1;
boardObj[iObj][jObj] = lettersObj[0];
while (kObj < 26) {
directionObj = rand() % 4;
switch (directionObj) {
case 0: if (boardObj[iObj][jObj + 1] == '.' && jObj != ROWSOBJ - 1){
boardObj[iObj][jObj +1] = lettersObj[kObj];
kObj++; jObj++;}
if (boardObj[iObj][jObj + 1] != '.' && boardObj[iObj + 1][jObj] != '.' && boardObj[iObj - 1][jObj] != '.' && boardObj[iObj][jObj - 1] != '.')
kObj = 27;
break;   
case 1: if (boardObj[iObj + 1][jObj] == '.' && iObj != COLSOBJ -1) {
boardObj[iObj + 1][jObj] = lettersObj[kObj];
kObj++; iObj++; }
if (boardObj[iObj][jObj + 1] != '.' && boardObj[iObj + 1][jObj] != '.' && boardObj[iObj - 1][jObj] != '.' && boardObj[iObj][jObj - 1] != '.')
kObj = 27;
break;
case 2: if (boardObj[iObj - 1][jObj] == '.' && iObj != 0){
boardObj[iObj - 1][jObj] = lettersObj[kObj];
kObj++; iObj--; }
if (boardObj[iObj][jObj + 1] != '.' && boardObj[iObj + 1][jObj] != '.' && boardObj[iObj - 1][jObj] != '.' && boardObj[iObj][jObj - 1] != '.')
kObj = 27;
break;
case 3: if (boardObj[iObj][jObj - 1] == '.' && jObj != 0) {
boardObj[iObj][jObj - 1] = lettersObj[kObj];
kObj++; jObj--;}
if (boardObj[iObj][jObj + 1] != '.' && boardObj[iObj + 1][jObj] != '.' && boardObj[iObj - 1][jObj] != '.' && boardObj[iObj][jObj - 1] != '.')
kObj = 27;
break;
}
}
for (iObj = 0; iObj < ROWSOBJ; iObj++) {
for (jObj = 0; jObj < COLSOBJ; jObj++)
printf ("%4c", boardObj[iObj][jObj]);
printf ("\n");
}

return 0;

}

Output screenshot:

Add a comment
Know the answer?
Add Answer to:
C Programming. Write a prograrm that generates a "random walk" across a 10 × 10 array....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Write a program that generates and prints 24 random values using an array and the...

    C++ Write a program that generates and prints 24 random values using an array and the rand () function. Implement an algorithm to find the maximum and a minimum number of random numbers generated. Use the header "#include <ctime>", "#include <cstdlib>" in addition to the usual header: "#include <iostream>"

  • Having issues using binary search on a pointer array. 1. Write 1000 random ints to file...

    Having issues using binary search on a pointer array. 1. Write 1000 random ints to file 2. Binary Search to find if number exists in element from file. int main() { ArrayActions action;   int count; int userInput; int num = 1000; int array[num]; ofstream myFile ("/Users/chan/Desktop/LANEY_CIS27/Assignemtn2_CIS27/Assignemtn2_CIS27/File.txt");   //Set srand with time to generate unique random numbers srand((unsigned)time(0));   //Format random num up to 999 for(count = 0; count < num; count++) { array[count] = rand() % 1000; }          //Condition...

  • MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random...

    MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random words from a training set as explained in the lectures on graphs. Do not hard-code the training set! Read it from a file. A suggested format for the input file: 6 a e m r s t 10 ate eat mate meet rate seat stream tame team tear Here are some suggestions for constants, array declarations, and helper functions #include <iostream> #include <fstream> #include...

  • Problem: Write a program that generates random numbers between 1 and 10 and fill an array...

    Problem: Write a program that generates random numbers between 1 and 10 and fill an array of size 20 with them. Have your program sort the array then output in order the number of occurrences of each random number generated. Use the STL sort function to sort your array. How to use the STL sort: #include <algorithm> ... int a[20] ... sort(a,a+20); Example Output: This program generates random numbers and tabulates the results Original List Sorted: a[ 0] 1 a[...

  • Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive...

    Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Your implementation must have a level of modularity (using functions) Functions you need to implement: Define function initialize() that takes array lotterNumbers[] as a parameter and assigns...

  • I need Help PLZ. I can't solving this in C program Given is a C program count_primes.c, which is an array Generates 10000 six-digit random numbers and then determines the number of primes in that...

    I need Help PLZ. I can't solving this in C program Given is a C program count_primes.c, which is an array Generates 10000 six-digit random numbers and then determines the number of primes in that array. It also measures the time that elapses during the calculation and returns it to the console along with the number of primes it finds. (a) Rewrite the program so that N threads are used to count the primes in the array. Each thread is...

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

  • !!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random...

    !!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random text with my generateText method, you can move on to the second step. Create a third class called Generator within the cs1410 package. Make class. This class should have a main method that provides a user interface for random text generation. Your interface should work as follows: Main should bring up an input dialog with which the user can enter the desired analysis level...

  • I need a basic program in C to modify my program with the following instructions: Create...

    I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...

  • in c++ please program for this code #include <iostream> #include <fstream> #include <string> #include <cstring> //...

    in c++ please program for this code #include <iostream> #include <fstream> #include <string> #include <cstring> // for string tokenizer and c-style string processing #include <algorithm> // max function #include <stdlib.h> #include <time.h> using namespace std; // Extend the code here as needed class BTNode{ private: int nodeid; int data; int levelNum; BTNode* leftChildPtr; BTNode* rightChildPtr; public: BTNode(){} void setNodeId(int id){ nodeid = id; } int getNodeId(){ return nodeid; } void setData(int d){ data = d; } int getData(){ return data;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT