CODE IN C /** * Function: weird_sums * Description: replaces each matrix element
ID: 648747 • Letter: C
Question
CODE IN C /** * Function: weird_sums * Description: replaces each matrix element m[i][j] with the sum of: * * - itself and * - the sum of all elements which are BOTH ABOVE IT AND * TO ITS LEFT * * Illustration: consider the matrix element labeled X below. * It will be replaced with the sum of itself (X) * and all matrix elements marked * * * ***...... * ***...... * ***...... * ...X..... * ......... * ......... * ......... * * Example: * * 1 3 2 2 * 6 1 9 8 * 5 7 2 8 * * will become * * 1 3 2 2 * 6 2 13 14 * 5 14 13 30 */ extern void mtx_weird_sums(int m[][NCOLS], int nrows);
Explanation / Answer
#include <stdio.h>
int main()
{
int m[3][4];
int i=4,j=3,number;
for(i=0;i<3;i++){
for(j=0;j<4;j++){
printf("enter number");
scanf("%d",&number);
m[i][j]=number;
}
}
int rowa= mtx_weird_sums(m, 4);
return 0;
}
int mtx_weird_sums(int a[3][4], int nrows)
{
int i,j,k,l,sum,b[3][4];
for(i=0;i<3;i++){
for(j=0;j<4;j++){
sum=a[i][j];
for(k=0;k<i;k++){
for(l=0;l<j;l++){
sum=sum+a[k][l];
}
}
b[i][j]=sum;
}
}
for(i=0;i<3;i++){
for(j=0;j<4;j++){
printf("%d ",b[i][j]);
}
printf(" ");
}
return nrows;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.