Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why does it show that variable 'i' undeclared in loop? (C language)

–8 votes
asked Jun 7, 2021 by tearaj (150 points)

#include<stdio.h>

int main()

{

    int a[5][5],b[5][5],r1,c1;

    printf("Enter number of rows and columns: ");

    scanf("%d%d",&r1,&c1);

    printf("Enter the values of the matrix: ");

    

    for(int i=0;i<r1;i++); 

    {

        for(int j=0;j<c1;j++)

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

    }

    

    printf("\nThe matrix is:\n");

    for(int i=0;i<r1;i++);

    {

        for(int j=0;j<c1;j++)

        printf("%d\t"a[i][j]);

        printf("\n");

    }

}

Note that the program isnt fully completed and that the program does work if i declare them outside both the loops. 

Program is written in C language.

13 Answers

0 votes
answered Jun 21, 2021 by emm-design (200 points)

kindly place a datatype 

like

for(int i=1;i<=10;i++)

0 votes
answered Jun 22, 2021 by Siddharth Patidar (140 points)
#include<stdio.h>

int main()

{

    int a[5][5],b[5][5],r1,c1;

    printf("Enter number of rows and columns: ");

    scanf("%d%d",&r1,&c1);

    printf("Enter the values of the matrix: ");

    for(int i=0;i<r1;i++)
    {
        for(int j=0;j<c1;j++)
        scanf("%d",&a[i][j]);

    }

    

    printf("\nThe matrix is:\n");

    for(int i=0;i<r1;i++)

    {
       for(int j=0;j<c1;j++)
          printf("%d\t", a[i][j]);

        printf("\n");

    }

}
0 votes
answered Jun 26, 2021 by Abhishek Khapariye (140 points)
putting semicolon after for loop means single statement without curly braces  which is valid for compiler but( ;) is not a statement .

 its like:

for( ; ;)

{

  ;

    }
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...