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

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()...
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 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 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...
Using the C Programming language, write a program that sums an array of 50 elements. Next,...
Using the C Programming language, write a program that sums an array of 50 elements. Next, optimize the code using loop unrolling. Loop unrolling is a program transformation that reduces the number of iterations for a loop by increasing the number of elements computed on each iteration. Generate a graph of performance improvement. Tip: Figure 5.17 in the textbook provides an example of a graph depicting performance improvements associated with loop unrolling. Marking:- Optimize the code for an array of...
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)
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...
C++ Program: Write another program (in C++) that will allocate a local static array of integers...
C++ Program: Write another program (in C++) that will allocate a local static array of integers and then a dynamic array of integers. Are they stored next to each other? You can examine this by examining the memory addresses where they are located. As described in class, on some systems the size of a dynamic array is actually stored in the bytes previous to a dynamically allocated array. Through some experiments on your own, try to see if this is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT