1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Zina [86]
3 years ago
10

SOLVE IN C:

Computers and Technology
1 answer:
RSB [31]3 years ago
4 0

Answer:

#include <stdio.h>

#include <string.h>

int main(void) {

  char simonPattern[50];

  char userPattern[50];

  int userScore;

  int i;

  userScore = 0;

  scanf("%s", simonPattern);

  scanf("%s", userPattern);

  for(i = 0;simonPattern[i]!='\0';i++){

         if(simonPattern[i]!=userPattern[i]){

            userScore=i;

            break;

     }

  }

  printf("userScore: %d\n", userScore);

  return 0;

}

Explanation:

  • Use a for loop that runs until it does not reach the end of simonPattern.
  • Check whether the current index of simonPattern and userPattern are not equal and then assign the value of i variable to the userScore variable and break out of the loop.
  • Finally display the user score.
You might be interested in
Fill in the function shopSmart(orders,shops) in shopSmart.py, which takes an orderList (like the kind passed in to FruitShop.get
ira [324]

Answer:

def shopSmart(orderList, fruitShops):  #function definition

   shop = fruitShops[0] #sets the shop to first item of fruitShops list

   leastAmount = shop.getPriceOfOrder(orderList)  #passes the orderList to getPriceOfOrder method which returns the total cost and saves it to leastAmount

   for fruitshop in fruitShops[1:]:  #iterates through the shops in fruitShops list

    cost = fruitshop.getPriceOfOrder(orderList)  #checks each cost or order using getPriceOfOrder method and passing orderList to it

    if cost < leastAmount:  #checks where order costs the least amount in total

     shop = fruitshop  #sets the FruitShop where order costs the least amount in total

     leastAmount = cost  #sets that minimum of order cost to leastAmount

   return shop #returns the FruitShop where order costs the least amount in total

Explanation:

Here are the getPriceOfOrder() and getName()) methods that is used in the above method.

def getPriceOfOrder(self, orderList):        

       totalCost = 0.0              

       for fruit, numPounds in orderList:

           costPerPound = self.getCostPerPound(fruit)

           if costPerPound != None:

               totalCost += numPounds * costPerPound

       return totalCost

def getName(self):

       return self.name

Here is the main program:

orders = [('apples',1.0), ('oranges',3.0)]

dir1 = {'apples': 2.0, 'oranges':1.0}

shop1 =  shop.FruitShop('shop1',dir1)

dir2 = {'apples': 1.0, 'oranges': 5.0}

shop2 = shop.FruitShop('shop2',dir2)

shops = [shop1, shop2]

print("For orders ", orders, ", the best shop is", shopSmart(orders, shops).getName())

orders = [('apples',3.0)]

print("For orders: ", orders, ", the best shop is", shopSmart(orders, shops).getName())

Notice that the statement:

print("For orders ", orders, ", the best shop is", shopSmart(orders, shops).getName())

has orders list which is:

[('apples',1.0), ('oranges',3.0)]

and it has shops which is a list containing two shops:

shops = [shop1, shop2]

It also calls method shopSmart by passing orders and these two shops to get the shop where the order costs the least amount in total. It has a for loop that iterates through each shop and check the orders using getPriceOfOrder method to determine at which shop the order costs the least amount in total. When the least amount is found it is set to the variable leastAmount and the shop corresponding to this order which has least amount is set to shop variable. At the end this shop is returned by the function. getName() method is used in the main program to get the name of the shop with least amount of order cost. So above print statement gives the following output:

For orders  [('apples', 1.0), ('oranges', 3.0)] , the best shop is shop1    

The entire program along with its output is attached.                                

8 0
4 years ago
What is a hobbyist for engineering
Nimfa-mama [501]
I believe its when some one does engineering as a hobby.
3 0
3 years ago
What observational data required the revision of the early geocentric model?
Diano4ka-milaya [45]
Graphic designer sketch geocentric model
3 0
3 years ago
Which component, located on the motherboard, carries out all the instructions provided by computer programs? ram?
Blababa [14]
<span>The Chipset is the component located on the motherboard, this carries out all the instructions provided by computer programs. It is the integrated circuit that manages all the data flow between processor and memory. It usually works with microprocessors and plays a crucial role in determining system performance.</span>
6 0
3 years ago
Which tags do you use to write the header and items of an ordered list on a web page?
Blababa [14]

Answer:

H1 tag and LI tag

hopefully it will help you

4 0
3 years ago
Other questions:
  • How to write equal to or greater than in word?
    9·1 answer
  • Which of the following statements is false? Speaking to your computer is a form of input. Playing a video is an example of outpu
    10·1 answer
  • Describe your microsoft word skills that need to be improved upon the most.<br><br>​
    8·1 answer
  • A primary mailing list for new vulnerabilities, called simply __________, provides time-sensitive coverage of emerging vulnerabi
    10·1 answer
  • What feature is required to send data from a web-connected device (like a point-of-sale system) to Google Analytics?
    14·1 answer
  • How could a system be designed to allow a choice of operating systems from which to boot? What would the bootstrap program need
    14·1 answer
  • Write a program that performs the following tasks: Display a friendly greeting to the user Prompt the user for the value to conv
    13·1 answer
  • In this program you will read in the number of seconds and convert it to days, hours, minutes and remaining seconds.
    8·1 answer
  • c) If you are at foreign country visit, which banking card would you prefer to keep with you during visit (Debit Card or Credit
    10·1 answer
  • What is responsible for what you see on the monitor?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!