View input and sum rows and columns
Hi, I need to fix a program with a main menu that prints the input inserted, sums the rows and sums the columns.
I made something up but it doesn't work and I can't understand why.
Here are the problems:
The function 2 prints random numbers in a loop.
The function 3 doesn't print anything
The function 4 prints just "0".
Code:
#include<stdio.h>
#include<string.h>
int main(void)
{
int selection;
int matrice[30][30];
int i;
int j;
int m;
int n;
int MAXn;
int vet;
do {
printf
("+----------------------------------------------------------------------------------------------+\n");
printf("1) input \n");
printf("2) view input \n3) sum rows\n4) sum colums \n9) exit\n--->");
scanf("%d", &selection);
if (selection == 1) {
printf("how many numbers will be inserted? ");
scanf("%d", &n);
printf("input a sequence of %d numbers\n", n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
printf("element %d: ", i + 1);
scanf("%d", &matrice[j]);
}
printf("\n");
}
}
if (selection == 2) {
printf("the sequence is the following:\n");
for (i = 0; i < n; i++)
for (j = 0; i < n; j++)
printf("element %d: %d\n", i + 1, matrice[j]);
printf("\n");
}
if (selection == 3) {
int somma;
for (i = 1; i <= n; i++) {
int somma = 0;
for (j = 1; i <= m; i++) {
somma = somma + matrice[j];
printf("sum: %d", &matrice[j]);
}
printf("sum: %d", somma);
}
}
if (selection == 4) {
int somma;
int righe;
int colonne;
int a[10][10];
for (righe = 0; righe < i; righe++) {
somma = 0;
for (colonne = 0; colonne < j; colonne++) {
somma = somma + a[colonne][righe];
}
printf("The sum of Column Elements in a Matrix = %d \n", somma);
}
}
if (selection > 10) // errore
{
printf("your choice is not valid");
}
if (selection == 9) {
printf("Exiting...");
getc;
}
}
while (selection != 9);
}