Question

In: Computer Science

Please Solve with c language Create 5-by-5 integer array. Initialize the elements of the array starting...

Please Solve with c language

Create 5-by-5 integer array.

Initialize the elements of the array starting from 1.

Your element [0][0] should be equal to 1; element[4][4] should be equal 25. Print the array.

The output should have 5 rows and 5 columns. Specify the width for each output to demonstrate the table in a formatted view.

Change the value of the elements: 2nd row 4th column to 24, 1st row 3rd column to 13.

Print the array again.

Find the sum of all the elements. Find the sum of all the elements of the first row.

Find the sum of all the elements of the third column.

Find the smallest element of the array.

Solutions

Expert Solution

#include<iostream>
using namespace std;
void printArray(int arr[][5]){
        for(int i=0;i<5;i++){
                for(int j=0;j<5;j++){
                        printf("%3d",arr[i][j]);
                }
                printf("\n");
        }
        printf("\n\n");
}
int main(){
        int arr[5][5];
;int val=1,sumOfElements=0,sumOfFirstRow=0,sumOfThirdColumn=0,min;
        for(int i=0;i<5;i++){
                for(int j=0;j<5;j++){
                        arr[i][j]=val++;
                }
        }
        printArray(arr);
        arr[1][3]=24;
        arr[0][2]=13;
        printArray(arr);
        for(int i=0;i<5;i++){
                sumOfFirstRow+=arr[0][i];
        }
        for(int i=0;i<5;i++)
                sumOfThirdColumn+=arr[i][2];
        min=arr[0][0];
        for(int i=0;i<5;i++){
                for(int j=0;j<5;j++){
                        sumOfElements+=arr[i][j];
                        if(min>arr[i][j])
                                min=arr[i][j];
                }
        }
        printf("Sum of all elements: %d\n",sumOfElements);
        printf("Sum of first row elements: %d\n",sumOfFirstRow);
        printf("Sum of third column elements: %d\n",sumOfThirdColumn);
        printf("Min element in the array: %d\n",min);
        
        
        
}

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME


Related Solutions

In C++, create a 3-by-3 array that is capable of storing integers and initialize each entry...
In C++, create a 3-by-3 array that is capable of storing integers and initialize each entry to 0. Ask the user to supply a row and a column and a value, then put the value into the array at that row and column. Print the array to the screen as a table with 3 rows and 3 columns, and ask the user for another row, column, and value. Repeat until user inputs values for all entries. Once finished, compute and...
Write a C function to swap the first and last elements of an integer array. Call...
Write a C function to swap the first and last elements of an integer array. Call the function from main() with an int array of size 4. Print the results before and after swap (print all elements of the array in one line). The signature of the arrItemSwap() function is: void arrItemSwap(int *, int, int); /* array ptr, indices i, j to be swapped */ Submit the .c file. No marks will be given if your pgm does not compile...
.data A: .space 80 # create integer array with 20 elements ( A[20] ) size_prompt: .asciiz...
.data A: .space 80 # create integer array with 20 elements ( A[20] ) size_prompt: .asciiz "Enter array size [between 1 and 20]: " array_prompt: .asciiz "A[" sorted_array_prompt: .asciiz "Sorted A[" close_bracket: .asciiz "] = " search_prompt: .asciiz "Enter search value: " not_found: .asciiz " not in sorted A" newline: .asciiz "\n" .text main: # ---------------------------------------------------------------------------------- # Do not modify la $s0, A # store address of array A in $s0 add $s1, $0, $0 # create variable "size" ($s1)...
1) Dynamic Allocation (c++) a. Create two integer variables x and y, initialize them with different...
1) Dynamic Allocation (c++) a. Create two integer variables x and y, initialize them with different values. b. Use dynamic memory allocation, declare px and py as address of x and y separately. c. Print out x, y, px, py, &x, &y, *px, *py.   d. Let py = px, and *py = 100 e. Print out x, y, px, py, &x, &y, *px, *py. g. Print out *px++, x, px
Write a c program Write a function to swap two elements of an integer array. Call...
Write a c program Write a function to swap two elements of an integer array. Call the function to swap the first element, i[0] with last element i[n], second element i[1] with the last but one element i[n-1] and so on. Should handle arrays with even and odd number of elements. Call the swap function with the following arrays and print results in each case before and after swapping. i. int arr1[] = {0, 1, 2, 3, 30, 20, 10,...
c++ language Create a file program that reads an int type Array size 10; the array...
c++ language Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.
Initialize and Print an Array Write a program that accepts two integer values, called "arraySize" and...
Initialize and Print an Array Write a program that accepts two integer values, called "arraySize" and "multiplier", as user input. Create an array of integers with arraySize elements. Set each array element to the value i*multiplier, where i is the element's index. Next create two functions, called PrintForward() and PrintBackward(), that each accept two parameters: (a) the array to print, (b) the size of the array. The PrintForward() function should print each integer in the array, beginning with index 0....
Write a c program arrays2.c that checks if an integer array contains three identical consecutive elements....
Write a c program arrays2.c that checks if an integer array contains three identical consecutive elements. Assume the number of identical consecutive elements are no more than three if they exist. Sample input/output #1: Enter the length of the array: 11 Enter the elements of the array: -12 0 4 2 2 2 36 7 7 7 43 Output: The array contains 2 of three identical consecutive elements: 2 7 Sample input/output #2: Enter the length of the array: 4...
In C language: Write a function which can receive a float array, an integer number(number of...
In C language: Write a function which can receive a float array, an integer number(number of elements) as input arguments and print all the elements in the array with 2 decimal precision.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT