In: Computer Science
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,j;
int size=10;
int carPosition[10];
int gameRunning = 1;
int time=1;
for(i=0;i<size;i++){
carPosition[i]=0;
}
while(gameRunning){
printf("\nTime : %d\n",time);
time++;
for(i=0;i<size;i++){
char
car='A'+i;
for(j=0;j<size;j++){
if(j==carPosition[i]){
printf("%c",car);
}else{
printf("%c",'.');
}
}
printf("\n");
carPosition[i]
+= rand()%2;
}
for(i=0;i<size;i++){
char
car='A'+i;
if(carPosition[i]==size){
printf("Car %c won the race",car);
gameRunning = 0;
}
}
}
return 0;
}