Question

In: Computer Science

Write a program in C that does the following: 1. Declares an array called numbers_ary of...

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

  • Using arrays (3)
  • Using loops (3)
  • Correct logic (2)
  • Correct output (2)

Solutions

Expert Solution

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:


Related Solutions

Write a program in C that declares the following array: int. array[] = { 1, 2,...
Write a program in C that declares the following array: int. array[] = { 1, 2, 4, 8, 16, 32 } Then write some code that accepts a number between 0 and 5 from the user and stores it in a variable called "index". Write some code that retrieves the item specified by the index, like this: int item = array[index]; Then write code that outputs the corresponding array entry based on the number the user entered. Example output: The...
Part 1:Write a program in Java that declares an array of 5 elements and displays the...
Part 1:Write a program in Java that declares an array of 5 elements and displays the contents of the array. Your program should attempt to access the 6th element in the array (which does not exist) and using try. catch your program should prevent the run-time error and display your error message to the user. The sample output including the error message is provided below. Part (1) Printing an element out of bounds 5 7 11 3 0 You went...
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements....
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements. Fill the array with random integers (use a loop). Neatly output each element in the one-dimensional array. Next convert your one-dimensional array of 24 elements into a two-dimensional array of 6 x 4 elements. Neatly output each element of the two-dimensional array. The values will be identical to the one-dimensional array – you’re just converting from one dimension to two.
Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant...
Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant float variable NJSALES_TAX; declares and initializes to 1000 an integer variable total; declares and initializes to zero a float variable grand_total; prompt and input on new line total; calculate grand_total to equal total plus (total*NJSALES_TAX); if grand_total <= 1000 print on new line “Grand total is less than or equal to 1000 it is $” and the grand_total to two decimal places; else if...
write the code that declares an array of booleans, called myarray, with size of 40 elements
write the code that declares an array of booleans, called myarray, with size of 40 elements
Program in C: Write a program in C that reorders the elements in an array in...
Program in C: Write a program in C that reorders the elements in an array in ascending order from least to greatest. The array is {1,4,3,2,6,5,9,8,7,10}. You must use a swap function and a main function in the code. (Hint: Use void swap and swap)
Given the following array, write a program in C++ to sort the array using a selection...
Given the following array, write a program in C++ to sort the array using a selection sort and display the number of scores that are less than 500 and those greater than 500. Scores[0] = 198 Scores[3] = 85 Scores[6] = 73 Scores[9] = 989 Scores[1] = 486 Scores[4] = 216 Scores[7] = 319 Scores[2] = 651 Scores[5] = 912 Scores[8] = 846
Write a program the declares and uses two parallel arrays. One array for storing the names...
Write a program the declares and uses two parallel arrays. One array for storing the names of countries and a second array for storing the populations of those countries. As you can see per the following the Country name and it's corresponding Population are stored at the same element index in each array. China 1367960000 India 1262670000 United States 319111000 Indonesia 252164800 Brazil 203462000 Pakistan 188172000 Nigeria 178517000 Bangladesh 157339000 Russia 146149200 Japan 127090000 In the main method write a...
Write a program the declares and uses two parallel arrays. One array for storing the names...
Write a program the declares and uses two parallel arrays. One array for storing the names of countries and a second array for storing the populations of those countries. As you can see per the following the Country name and it's corresponding Population are stored at the same element index in each array. China 1367960000 India 1262670000 United States 319111000 Indonesia 252164800 Brazil 203462000 Pakistan 188172000 Nigeria 178517000 Bangladesh 157339000 Russia 146149200 Japan 127090000 In the main method write a...
Write a program that does the following in C++ 1 ) Write the following store data...
Write a program that does the following in C++ 1 ) Write the following store data to a file (should be in main) DC Tourism Expenses 100.20 Revenue 200.50 Maryland Tourism Expenses 150.33 Revenue 210.33 Virginia Tourism Expenses 140.00 Revenue 230.00 2 ) Print the following heading: (should be in heading function) Store name | Profit [Note: use setw to make sure all your columns line up properly] 3 ) Read the store data for one store (should be in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT