Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have written this program using C Programming language which puts a 1 in the center of a 5 x 5 array and then has
I have written this program using C Programming language which puts a in the center of a x array and then has four commands up down left right to move the around in the array.
I already implemented the down command. So you would just need to implementfinish the other three up left, right Basically, you just need to figure out how to change the row,col correctly for the other three commands so its only a few lines of code to add
Here is the code:
#include
#include
#include
#define CRTSECURENOWARNINGS
void printitint data
for int i ; i ; i
for int j ; j ; j
printfd dataij;
printf
;
printf
;
void clearint data
for int i ; i ; i
for int j ; j ; j
dataij;
int main
char sentence;
char firstword;
int x;
int row, col;
int args;
int arr;
printfu # will move the one up # times
;
printfd # will move the one down # times
;
printfl # will move the one left # times
;
printfr # will move the one right # times
;
printfexit will leave
;
cleararr;
arr;
printitarr;
row ;
col ;
for ;;
printfenter your command;
empty out the string just to be safe
strcpysfirstword;
strcpyssentence;
suck in a sentence from the user into memory
getsssentence;
suck from our sentence a word followed by two doubles
args sscanfssentences d firstword, unsignedcountofsentence &x;
compare the first word to quit
if strcmpfirstword "exit"
printfgoodbye;
break;
else if strcmpfirstwordu
if args x ;
printfrow is d col is d
row, col;
else if strcmpfirstwordd
if args x ;
printfrow is d col is d
row, col;
for int i ; i x; i
row absrow ;
cleararr;
arrrowcol;
printitarr;
else if strcmpfirstwordl
if args x ;
printfrow is d col is d
row, col;
else if strcmpfirstwordr
if args x ;
printfrow is d col is d
row, col;
else
printfdont understand that";
return;
Once you finish the code I want you to turn it in testing it on following output:
Do a
l goes left and prints the matrix a total of three times notice how it should wrap around to the right
Then do a
u goes up and prints the matrix a total of two times
IN ThE LAST MATRIX THE ONE SHOULD WIND UP IN THE RIGHT TOP CORNER OF THE GRID
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started