Question

In: Computer Science

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.

Solutions

Expert Solution

#include <stdio.h>

#include <stdlib.h>

// Driver program

int main(void)

{

int arr[24];

int arr1[6][4];

for(int i = 0; i<24; i++)

arr[i]=rand()%1000;

for(int i = 0; i<24; i++)

printf("%d ",arr[i]);

printf("\n\n\n");

int index=0;

for(int i=0;i<6;i++)

for(int j=0;j<4;j++)

arr1[i][j]=arr[index++];

for(int i=0;i<6;i++){

for(int j=0;j<4;j++)

printf("%5d ",arr1[i][j]);

printf("\n");

}

return 0;

}


Related Solutions

2. Write a program in C++ that: a) Declares a 1D array A with 30 elements...
2. Write a program in C++ that: a) Declares a 1D array A with 30 elements b) Inputs an integer n from 1-30 from the keyboard. If n < 1 set n = 1. If n > 30 set n = 30. the program should keep asking the user the input n one by one, followed by printing of the value of n (n=n if bigger than 1 and smaller than 30, 1 if smaller than 1 and 30 if...
Write a program in C++ that declares an array of 100 integers named scores[]. Prompt the...
Write a program in C++ that declares an array of 100 integers named scores[]. Prompt the user for how many scores they want to enter. Then read in the specified number of ints and store them in the array. Then prompt the user for a passing grade. Use a for loop to go trough the array and count how many scores are passing. Print the count of how many passing scores, and also print a double that is the percent...
Write a C++ program that declares three one-dimensional arrays named miles, gallons and mpg. Each array...
Write a C++ program that declares three one-dimensional arrays named miles, gallons and mpg. Each array should be capable of holding 10 elements. In the miles array, store the numbers 240.5, 300.0 189.6, 310.6, 280.7, 216.9, 199.4, 160.3, 177.4 and 192.3. In the gallons array, store the numbers 10.3, 15,6, 8.7, 14, 16.3, 15.7, 14.9, 10.7 , 8.3 and 8.4. Each element of the mpg array should be calculated as the corresponding element of the miles array divided by the...
In C Write a program to read a one-dimensional array, print sum of all elements using...
In C Write a program to read a one-dimensional array, print sum of all elements using Dynamic Memory Allocation.
Write C program that reorders elements of an array of integers such that the new order...
Write C program that reorders elements of an array of integers such that the new order is in descending order (first number being the largest). Must have a main function and a swap function. - int main() will declare an array with the values { 32, 110, 79, 18, 22, 2}. This array will be passed to the swap function. - the void swap function will perform the necessary operations to reorder the elements of the array. - After swap()...
Write a C++ program to find K largest elements in a given array of integers. For...
Write a C++ program to find K largest elements in a given array of integers. For eeample, if K is 3, then your program should ouput the largest 3 numbers in teh array. Your program is not supposed to use any additional array.
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers...
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers as follows: Assign {35,20,-43,-10,6,7,13} -Create a one dimensional array of 7 Boolean values as follows: Assign {true,false,false,true,false,true,false} -Create a one dimensional array of 7 floating-point values as follows: Assign {12.0f,1.5f,-3.5f,-2.54f,3.4f,45.34f,22.13f} -Declare sum as integer and set it to 0. -Declare sumf as float and set it to 0.0f. -Use a for loop to go through each element of the Boolean array, and if an...
write three functions in C++: one that declares a large array statically, one that declares the...
write three functions in C++: one that declares a large array statically, one that declares the same array on the stack, and one that creates the same array on the heap. Call each of them a number of times (at least 100,000) and output the time required by each. Explain the results.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT