main(){
int TwoDi [2][3];
int row=0;
int col=0;
int numb=0;
int loc=0;
int val=0;
for(row=0;row<2;row++){
for(col=0;col<3;col++){
printf("The Variable is ");
scanf("%d",&val);
}
}
for(row=0;row<2;row++){
for(col=0;col<3;col++){
loc=TwoDi[row][col];
}
}
printf("%d",loc);
getche();
}
maybe this is the sample output
Enter a Number [0][0] : 87
Enter a Number [0][1] : 88
Enter a Number [0][2] : 89
Enter a Number [1][0] : 90
Enter a Number [1][1] : 91
Enter a Number [1][2] : 92
Search a Number : 90
Index Location : Row 1 Column 0
int main()
{
int TwoDi [2][3];
int numb;
for(int row=0;row<2;row++)
{
for(int col=0;col<3;col++)
{
std::cout << "Enter number a number [%d][%d]" << row, col;
std::cin >> TwoDi[row][col];
}
}
std::cout << "\nSearch Number";
std::cin >> numb;
for(int row=0;row<2;row++)
{
for(int col=0;col<3;col++)
{
if(numb == TwoDi[row][col])
std::cout << "\nRow %d and Col %d"<< row,col;
}
}
getchar();
return 0;
}
But still I suggest you try (error and correct method) in your implementation so that you will learn about program as well and you know what is wrong with what point.
main(){
int TwoDi [2][3];
int row=0;
int col=0;
int numb=0;
int val=0;
for(row=0;row<2;row++)
{
for(col=0;col<3;col++)
{
printf("The Variable is ");
scanf("%d",&TwoDi[row][col]);
}
}
printf("\nSearch Number ");
scanf("%d", &numb);
for(row=0;row<2;row++)
{
for(col=0;col<3;col++)
{
if(numb == TwoDi[row][col])
printf("The Location is : Row %d and Col %d", row,col);
}
}
getche();
}
Technically, in C or C++ main function has to return a value because it is declared as "int main"
which means "main function should return integer data type"
if main is declared like "void main", then there's no need of return 0.
Some compilers even accept and compile the code even if u dont write return 0. varies from compiler to compiler.
And also return 0 means that your program executed without errors .
To expand on the existing reply, when you run your program on your standard desktop operating system, the first thing that is run is not your function main. There are things that need to be done before your code can be started. Eventually, a function in the runtime gets around to calling your function main, just as if it were any other function. The runtime expects that the function main returns an int. There will be a place in memory where it expects to find that returned value.
Bad things can happen if the function does not return a value when it is expected to. Many runtimes on everyday operating systems can handle it. They can work around it when the programmer chooses to deliberately write bad code. There are systems where it can cause serious problems.