In: Computer Science
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.
#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