In: Computer Science
Write a program in C that does the following:
1. Declares an array called numbers_ary of 6 integer numbers.
2. Declares an array called numbers_ary_sq of 6 integer numbers.
3. Reads and sets the values of numbers_ary from the keyboard using a loop.
4. Sets the values of numbers_ary_sq to the square of the values in numbers_ary using a loop.
5. Displays the values of numbers_ary and the values of numbers_ary_sq beside each other using a loop.
Example Output
Assume that both arrays have only 3 integer numbers and numbers_ary has [2 3 4]. Then,numbers_ary_sq will have [4 9 16] and the following would be displayed:
2 -> 4
3 -> 9
4 -> 16
Rubrics
Program:
#include<stdio.h>
int main()
{
//declaration of the two arrays
int numbers_ary[6];
int numbers_ary_sq[6];
int i;
//accepting the integers from user/keyboard
printf("Enter the 6 integer numbers : \n\n");
for(i=0;i<=5;i++)
{
scanf("%d",&numbers_ary[i]);
}
//storing the square of each integers of numbers_ary into
numbers_ary_sq
for(i=0;i<=5;i++)
{
numbers_ary_sq[i]=numbers_ary[i]*numbers_ary[i];
}
//displaying the values of both the arrays besides each other
printf("\n\nThe values of numbers_ary and numbers_ary_sq:
\n\n");
for(i=0;i<=5;i++)
{
printf("%d -> %d\n",numbers_ary[i],numbers_ary_sq[i]);
}
return 0;
}
Output: