Respuesta :
Answer:
#include <stdio.h> // header file
#include <string.h> // header file
int main() // main function
{
char simonPattern[50]; // create array
char userPattern[50]; // create array
int userScore =0 ; //variable declaration
int k= 0; // variable declaration
userScore = 0; // variable declaration
strcpy (simonPattern, "RRGBRYYBGY"); // copy the characters
strcpy (userPattern, "RRGBBRYBGY"); // copy the characters
for(k=0; simonPattern[k]!='\0'; k++) // iterating the loop
{
if(simonPattern[k] == userPattern[k]) // checking the condition
{
userScore++; // increment the value
}
else
{
break; // break the loop
}
}
printf("User score = %d \n", userScore); // print the value
return 0;
}
Output:
user score = 4
Explanation of the program in steps is given below:
Step 1 : Declaring header files.
Step 2 : Creating main function.
Step 3 : Creating an array.
Step 4 : Declaring a variable then copy the characters with the help of "strcpy()" function.
Step 5 : Starts a loop, check the condition and incrementation in the value.
Step 6 : Print the value and return function.