Multiply elements on the secondary diagonal of an array. Borland C

687 views Asked by At

Here is what i have tried:

#include <conio.h>
#include <stdio.h>
// calculeaza produsul elementelor diagonalei secundare ale unei matrici
// 1 2 3
// 5 4 2
// 6 5 8 == 13
void main(){
    int a[20][20], i, j, n, p;
    printf("Dati numarul de linii si coloane a matricei:");
    scanf("%d", &n);
for(i=1; i<=n; i++)
for(j=1; j<=n; j++){
    printf("a["<<i<<","<<j<<"]=");
    scanf(a[i][j]);
}
p=1;
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
    if(i+j == n+1){
        p=a[i][j];
    }
printf("Produsul=%d", p);
getch ();
}

I get 3 errors though:

1.Illegal use of pointer, line 13.
2.Can not convert 'int' to 'const char *', line 14.
3.Type mismatch in parameter '_format' in call to 'scanf(const char *,...)'.

I can not figure this out, I did this in C++ but can not make it work in C.

2

There are 2 answers

0
Gopi On BEST ANSWER

Please check your printf() and scanf()'s.printf() can be use as

printf("a[%d,%d]=",i,j);

scanf() should be used as:

scanf("%d",&a[i][j]);
0
jez On

You cannot use << to work with strings in plain C. See the documentation on printf and scanf to see how to use them correctly.