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.
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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.