Question

4. write program to take two numerical lists of the same length ended by a sen- 4. a tinel value and store the lists in arrays x and y, each of which has 20 elements. Let n be the actual number of data values in each list. Store the product of corresponding elements oflx and in a third a 2. also of size 20. Display the arrays x, y, and z in a three-column table. Then compute and d the square root of the sum of the items in z. Make up your own data, and be sure to test your program on at least one data set with number lists of exactly 20 items. One data set should have lists of 21 numbers, and one set should have significantly shorter lists.


needs to be written in C language. please show that code works in command prompt if possible.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C code:

#include <stdio.h>
#include <math.h>
#include <string.h>


int main()
{

   printf("Example 1\n");

   int array1[20];
   int array2[20];
   int arrayz1[20];

   for (int i = 0; i < 20; ++i)
   {
       array1[i] = i;
       array2[i] = i;
   }

   for (int i = 0; i < 20; ++i)
   {
       arrayz1[i] = array1[i] * array2[i] ;
   }
   printf("input array1 \n");
   for (int i = 0; i < 20; ++i)
   {
       printf("%i ", array1[i]);
   }
   printf("\ninput array2 \n");
   for (int i = 0; i < 20; ++i)
   {
       printf("%i ", array2[i]);
   }
   printf("\nProduct array\n");
   int sum = 0;
   for (int i = 0; i < 20; ++i)
   {
       printf("%i ", arrayz1[i]);
       sum = sum + arrayz1[i];
   }
   int sqrtt = sqrt(sum);
   printf("\nSquare Root of sum of all elements in Z %i \n", sqrtt);
   printf("\n\nExample 2\n");

   int array3[21];
   int array4[21];
   int arrayz2[21];

   for (int i = 0; i < 21; ++i)
   {
       array3[i] = i;
       array4[i] = i;
   }

   for (int i = 0; i < 21; ++i)
   {
       arrayz2[i] = array3[i] * array4[i] ;
   }
   printf("input array1 \n");
   for (int i = 0; i < 21; ++i)
   {
       printf("%i ", array3[i]);
   }
   printf("\ninput array2 \n");
   for (int i = 0; i < 21; ++i)
   {
       printf("%i ", array4[i]);
   }
   printf("\nProduct Array \n");
   sum = 0;
   for (int i = 0; i < 21; ++i)
   {
       printf("%i ", arrayz2[i]);
       sum = sum + arrayz2[i];
   }
   sqrtt = sqrt(sum);
   printf("\nSquare Root of sum of all elements in Z %i \n", sqrtt);

   printf("\n\nExample 3\n");

   int array5[3];
   int array6[3];
   int arrayz3[3];

   for (int i = 0; i < 3; ++i)
   {
       array5[i] = i;
       array6[i] = i;
   }

   for (int i = 0; i < 3; ++i)
   {
       arrayz3[i] = array5[i] * array6[i] ;
   }
   printf("input array1 \n");
   for (int i = 0; i < 3; ++i)
   {
       printf("%i ", array5[i]);
   }
   printf("\ninput array2 \n");
   for (int i = 0; i < 3; ++i)
   {
       printf("%i ", array6[i]);
   }
   printf("\nProduct Array \n");
   sum = 0;
   for (int i = 0; i < 3; ++i)
   {
       printf("%i ", arrayz3[i]);
       sum = sum + arrayz3[i];
   }
   sqrtt = sqrt(sum);
   printf("\nSquare Root of sum of all elements in Z %i \n", sqrtt);
   printf("\n");

   return 0;
}

Sample Output:

Example 1
input array1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
input array2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Product array
0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361
Square Root of sum of all elements in Z 49


Example 2
input array1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
input array2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Product Array
0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400
Square Root of sum of all elements in Z 53


Example 3
input array1
0 1 2
input array2
0 1 2
Product Array
0 1 4
Square Root of sum of all elements in Z 2

Add a comment
Know the answer?
Add Answer to:
needs to be written in C language. please show that code works in command prompt if...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Program in C language for: 1. Create a C program to read 7 integers...

    Write a Program in C language for: 1. Create a C program to read 7 integers and store them in an array. Next, the program is to check if the array is symmetric, that is if the first element is equal to the last one, the value of the second one is equal to the value of the last but one, and so on. Since the middle element is not compared with another element, this would not affect the symmetry...

  • 2. a)Write the ARM ALP conditional code snippet for the following statements written in C-language. Assume R1 to Rn as06 variables Let R1, R2, R3 contain the starting addresses of arrays X, Y and Z r...

    2. a)Write the ARM ALP conditional code snippet for the following statements written in C-language. Assume R1 to Rn as06 variables Let R1, R2, R3 contain the starting addresses of arrays X, Y and Z respectively Use Register R4 for variable i. Display appropriate messages. While (i+10) else Z[i] XiYi; b)i Write a program to display a message "This is an examination Question" on the screen using 06 a function sub program Note the following Address of the string to...

  • Need help. Please write Python program that answer the prompt and has an sample output as...

    Need help. Please write Python program that answer the prompt and has an sample output as shown below. Thank you. We were unable to transcribe this imageCommand: view Number: 2 Name: Eric Idle Email: [email protected] Phone: +44 20 7946 0958 Command: add Name: Mike Murach Email: [email protected] Phone: 559-123-4567 Mike Murach was added. Command: del Number: 1 Guido van Rossum was deleted. Command: list 1. Eric Idle 2. Mike Murach Command: exit Thank you for using my app. Specifications Your...

  • *This is meant to be done in C++ language only* *Please consider the fact that I'm...

    *This is meant to be done in C++ language only* *Please consider the fact that I'm a beginner and want to be able to follow what you're doing so please write the code as simple and organized as possible. Thanks in advance. Create a program that uses an array(one dimensional) to store the results from a poll of 30 people. Each person was asked to estimate the amount of time, in minutes, that he or she spends on Facebook each...

  • Q4) Write a C program named "hw3q4.c” that takes three string inputs from the command line...

    Q4) Write a C program named "hw3q4.c” that takes three string inputs from the command line arguments that represent file names. The first and second files contain four sorted integer numbers that represent set elements. The main process creates a child process that shares the three files. The child process determines the intersection set of two sets and saves the line: "Child process PID: xxxx Intersection of (x, x, x, x) and (y, y, y, y) (z, z, z, z)"...

  • this assignment should be delivered in C language Program 4 will prompt the user for one...

    this assignment should be delivered in C language Program 4 will prompt the user for one or two token, space delimited, inputs of at most 20 characters. If the user provides more than 20 characters before a newline is reached print the provided error message. If the number of tokens is incorrect, print the appropriate error message. If the input is correct, print the appropriate token types. Prompt the user for input (and provide output) until the user provides a...

  • write a C programming code for the following prompt. please use stucture concept and test if...

    write a C programming code for the following prompt. please use stucture concept and test if the code works perfectly. Project Description: In this project, you will write a program to calculate the roots of a quadratic equation. Structure concepts will be used in this project. Your program will prompt the user to enter the coefficients of a quadra coefficientsType. Then it will compute the roots of the quadratic equation and store the result in a structure variable of type...

  • using C language Create an array of doubles with 5 elements. In the array prompt the...

    using C language Create an array of doubles with 5 elements. In the array prompt the user to enter 5 temperature values (in degree Fahrenheit). Do this within main. Create a user defined function called convert2Cels. This function will not return any values to main with a return statement. It should have parameters that include the temperature array and the number of elements. The function should convert the values for Fahrenheit to Celsius and save them back into the same...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

  • q13 c++ if answering please do not write code in paragrapth form. 13. Drink Machine Simulator...

    q13 c++ if answering please do not write code in paragrapth form. 13. Drink Machine Simulator Write a program that simulates a soft drink machine. The program should use a structure that stores the following data: Drink Name Drink Cost Number of Drinks in Machine The program should create an array of five structures. The elements should be initialized with the following data: Drink Name Cost Number in Machine Cola .75 20 Root Beer .75 20 Lemon-Lime .75 20 Grape...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT