Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3802504 • Letter: N

Question


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

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.

Explanation / Answer

C code:

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


int main()
{

   printf("Example 1 ");

   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 ");
   for (int i = 0; i < 20; ++i)
   {
       printf("%i ", array1[i]);
   }
   printf(" input array2 ");
   for (int i = 0; i < 20; ++i)
   {
       printf("%i ", array2[i]);
   }
   printf(" Product array ");
   int sum = 0;
   for (int i = 0; i < 20; ++i)
   {
       printf("%i ", arrayz1[i]);
       sum = sum + arrayz1[i];
   }
   int sqrtt = sqrt(sum);
   printf(" Square Root of sum of all elements in Z %i ", sqrtt);
   printf(" Example 2 ");

   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 ");
   for (int i = 0; i < 21; ++i)
   {
       printf("%i ", array3[i]);
   }
   printf(" input array2 ");
   for (int i = 0; i < 21; ++i)
   {
       printf("%i ", array4[i]);
   }
   printf(" Product Array ");
   sum = 0;
   for (int i = 0; i < 21; ++i)
   {
       printf("%i ", arrayz2[i]);
       sum = sum + arrayz2[i];
   }
   sqrtt = sqrt(sum);
   printf(" Square Root of sum of all elements in Z %i ", sqrtt);

   printf(" Example 3 ");

   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 ");
   for (int i = 0; i < 3; ++i)
   {
       printf("%i ", array5[i]);
   }
   printf(" input array2 ");
   for (int i = 0; i < 3; ++i)
   {
       printf("%i ", array6[i]);
   }
   printf(" Product Array ");
   sum = 0;
   for (int i = 0; i < 3; ++i)
   {
       printf("%i ", arrayz3[i]);
       sum = sum + arrayz3[i];
   }
   sqrtt = sqrt(sum);
   printf(" Square Root of sum of all elements in Z %i ", sqrtt);
   printf(" ");

   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