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
Alborosie
3 years ago
6

The following C program asks the user for two input null-terminated strings, each stored in uninitialized 100-byte buffer, and c

ompares them. The program then shows the alphabetical order of both strings, by reporting whether the first is less than the second, the second is less than the first, or both are equal.#include «stdio·h> int main() // Two strings, 100 bytes allocated for each char si [100; char s2 [100]; // Read string 1 printf("Enter string scanf("%s", s1); 1: "); // Read string 2 printf("Enter string scanf("%s", s2); 2: "); // Compare them int index = 0; while (1) / Load characters from s1 and s2 char c1 = s1[index]; char c2 = s2[index]; // Current character is greater for s1 if (c1 > c2) printf("s1 > s2\n") break; // Current character is greater for s2 if (c1 < c2) printf("s1
Engineering
1 answer:
marissa [1.9K]3 years ago
3 0

Answer:

Code is given below:

Explanation:

.data  

str1: .space 20  

str2: .space 20  

msg1:.asciiz "Please enter string (max 20 characters): "  

msg2: .asciiz "\n Please enter string (max 20 chars): "  

msg3:.asciiz "\nSAME"  

msg4:.asciiz "\nNOT SAME"  

.text

.globl main

main:  

   li $v0,4        #loads msg1  

   la $a0,msg1  

   syscall

   li $v0,8

   la $a0,str1

   addi $a1,$zero,20

   syscall          #got string to manipulate

   li $v0,4        #loads msg2

   la $a0,msg2

   syscall

   li $v0,8

   la $a0,str2

   addi $a1,$zero,20

   syscall         #got string  

       la $a0,str1             #pass address of str1  

   la $a1,str2         #pass address of str2  

   jal methodComp      #call methodComp  

   beq $v0,$zero,ok    #check result  

   li $v0,4

   la $a0,msg4

   syscall

   j exit

ok:  

   li $v0,4  

   la $a0,msg3  

   syscall  

exit:  

   li $v0,10  

   syscall  

methodComp:  

   add $t0,$zero,$zero  

   add $t1,$zero,$a0  

   add $t2,$zero,$a1  

loop:  

   lb $t3($t1)         #load a byte from each string  

   lb $t4($t2)  

   beqz $t3,checkt2    #str1 end  

   beqz $t4,missmatch  

   slt $t5,$t3,$t4     #compare two bytes  

   bnez $t5,missmatch  

   addi $t1,$t1,1      #t1 points to the next byte of str1  

   addi $t2,$t2,1  

   j loop  

missmatch:    

   addi $v0,$zero,1  

   j endfunction  

checkt2:  

   bnez $t4,missmatch  

   add $v0,$zero,$zero  

endfunction:  

   jr $ra

You might be interested in
Fix the code so the program will run correctly for MAXCHEESE values of 0 to 20 (inclusive). Note that the value of MAXCHEESE is
GarryVolchara [31]

Answer:

Code fixed below using Java

Explanation:

<u>Error.java </u>

import java.util.Random;

public class Error {

   public static void main(String[] args) {

       final int MAXCHEESE = 10;

       String[] names = new String[MAXCHEESE];

       double[] prices = new double[MAXCHEESE];

       double[] amounts = new double[MAXCHEESE];

       // Three Special Cheeses

       names[0] = "Humboldt Fog";

       prices[0] = 25.00;

       names[1] = "Red Hawk";

       prices[1] = 40.50;

       names[2] = "Teleme";

       prices[2] = 17.25;

       System.out.println("We sell " + MAXCHEESE + " kind of Cheese:");

       System.out.println(names[0] + ": $" + prices[0] + " per pound");

       System.out.println(names[1] + ": $" + prices[1] + " per pound");

       System.out.println(names[2] + ": $" + prices[2] + " per pound");

       Random ranGen = new Random(100);

       // error at initialising i

       // i should be from 0 to MAXCHEESE value

       for (int i = 0; i < MAXCHEESE; i++) {

           names[i] = "Cheese Type " + (char) ('A' + i);

           prices[i] = ranGen.nextInt(1000) / 100.0;

           amounts[i] = 0;

           System.out.println(names[i] + ": $" + prices[i] + " per pound");

       }        

   }

}

7 0
4 years ago
A wastewater is to be disinfected using ultraviolet (UV) light. Batch experiments find that the bacterial concentration decays u
Ksivusya [100]

Answer:

k = 0.1118 per min

Explanation:

Assume;

Initial number of bacteria = N0

Number of bacteria IN 'T' time = Nt

So,

Nt=N0e^{-kt}\\\\in\ 6.2 min\\\\\\frac{N0}{2}= N0e^{-k(6.2)}\\\\ln\frac{1}{2} = -k[6.2]

k = 0.1118 per min

7 0
3 years ago
Discuss four (4) advantages of direct and indirect water supply system.
Reil [10]

Answer and Explanation:

Some of the advantages of direct water supply system are:

  • Smaller size of the cistern
  • No risk of polluted water
  • Ease of installation
  • Lower pipe work

Some of the advantages of indirect water supply system are:

  • It can be pumped completely
  • Lower demand on the main source
  • Minimization of wear and tear on taps
  • Larger size of the cistern.
7 0
3 years ago
Read 2 more answers
1. One of these is NOT a type of pneumatic tool. Which one?
Serggg [28]

Answer:Circular

Explanation:

It’s the only thing not list under pneumatic tools‍♂️

5 0
3 years ago
An assembly line in a modern business compared to one from Henry Ford's time is more likely to rely on which of the following?
Pavel [41]

Answer:

d. fixed layouts

Explanation:

7 0
3 years ago
Other questions:
  • In , the industries with the most complaints to the Better Business Bureau were banks, cable and satellite television companies,
    13·1 answer
  • Match each context to the type of the law that is most suitable for it.
    7·1 answer
  • . On Juan's twenty-sixth birthday, he deposited $7,500 in a retirement account. Each year thereafter, he deposited $1,000 more t
    11·1 answer
  • You just graduate from college and find a job (yah! Congrats!). You buy a new house and would like to install solar panels for t
    5·1 answer
  • Determine size of a standard square key made of 1045 hot rolled steel for a 2 inch DIA shaft transmitting 100 HP at 500 rpm with
    12·1 answer
  • 1. In a mechanical design, it is recommended to use standard size/dimension to overcome uncertainties in stress or material stre
    7·1 answer
  • True or false a critique of hazwoper incidents that have occurred in the past year should not be included in hazwoper 8 hour ref
    6·1 answer
  • Whats a person who enters the electrical trade
    7·2 answers
  • state four reasons why public participation is important in ensuring sustainable provision of services to the community​
    13·1 answer
  • What are some benfits of getting involved with 4h
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!