'Getting this error: warning: too many arguments for format [-Wformat-extra-args] [closed]

  printf("\nEnter Matrix A\n", i + 1, j + 1);
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      scanf("%d", &a[i][j]);
    }

  printf("\nEnter Matrix B\n", i + 1, j + 1);
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      scanf("%d", &b[i][j]);
    }

When I compile this, I get an error message saying main.c:9:10: warning: too many arguments for format [-Wformat-extra-args] on lines 10 and 16. I’m new to programming C so any tips would be helpful.



Solution 1:[1]

Oh I see you are just missing the %i for your printf. No big deal. That what it was telling you. If this helps please give green check. Thank you

#include <stdio.h>

int main() {
  int r, c, a[100][100], b[100][100], sum[100][100], i, j;
  printf("Enter the number of rows: ");
  scanf("%d", &r);
  printf("Enter the number of columns: ");
  scanf("%d", &c);

  printf("\nEnter Matrix A\n %i,%i", i + 1, j + 1);
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      scanf("%d", &a[i][j]);
    }

  printf("\nEnter Matrix B\n %i,%i", i + 1, j + 1);
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      scanf("%d", &b[i][j]);
    }


  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      sum[i][j] = a[i][j] + b[i][j];
    }

  printf("\nA + B = \n");
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      printf("%d   ", sum[i][j]);
      if (j == c - 1) {
        printf("\n\n");
      }
    }

  return 0;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 boardkeystown