this is what problem 2 said As in the previous problem, copy the one-dimensional
ID: 3593244 • Letter: T
Question
this is what problem 2 said
As in the previous problem, copy the one-dimensional array from problem 2 into two two- dimensional arrays. 4. Store the data into a 5x5 array, filling the columns first and padding any unfilled elements with zeros. Store the data into a 5x5 array, but this time fill the rows before the columns, and padding any unfilled elements with zeros a. b. Be sure to print a line before printing the arrays, briefly saying which array is which. Then, print the array from part a with "R:"before each row and print the the array from part b with "C:" before each row. See the output below as a guide for what this should look like and the numerical format. You should experiment with the formats to see how to get this to happen. Second array, padded, filling columns first: C: 0.2481 -0.0495 -0.4162 -0.2711 0.0000 C: 0.4133 -0.3477 0.3258 0.0383 0.0000 C: 0.4961 -0.4219 -0.0574-0.3934 0.0000 C: 0.4618-0.4954 0.2749 0.3173 0.0000 C: 0.3686-0.4156 -0.1003-0.2402 0.0000 Second array, padded, filling rows first: R: 0.2481 0.4133 0.4961 0.4618 0.3686 R: -0.0495-0.3477 -0.4219 -0.4954-0.4156 R: -0.4162 0.3258 -0.0574 0.2749-0.1003 R: -0.2711 0.0383 -0.3934 0.3173-0.2402 R: 0.0000 0.0000 0.0000 0.0000 0.0000Explanation / Answer
#include <stdio.h>
/** funtion : readArray()
input : arr ( array of integer ), size
to read ONE-D integer array from standard input device (keyboard).
**/
void readArray(int arr[], int size)
{
int i =0;
printf(" Enter elements : ");
for(i=0; i < size; i++)
{
printf("Enter arr[%d] : ",i);
scanf("%d",&arr[i]);
}
}
/** funtion : printArray()
input : arr ( array of integer ), size
to display ONE-D integer array on standard output device (moniter).
**/
void printArray(int arr[],int size)
{
int i =0;
printf(" Elements are : ");
for(i=0; i < size; i++)
{
printf(" arr[%d] : %d",i,arr[i]);
}
printf(" ");
}
void merge(int arr1[], int size1, int arr2[], int size2, int arr3[])
{
int i = 0,j=0 ;
for(i=0; i < size1; i++)
arr3[i] = arr1[i];
for(i=5,j=0;i < size2+5; i++,j++)
arr3[i] = arr2[j];
}
int main()
{
int arr1[5];
int arr2[5];
int arr3[10];
readArray(arr1,5);
readArray(arr2,5);
merge(arr1, 5, arr2, 5, arr3);
printArray(arr3,10);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.