0
How can i create two dimensional array 15by15 and initialized by an incrementation ?
6 Respuestas
+ 3
Did you mean? Create 2 dimensional array 15x15 and assign value? what do you mean by incrementation? is it auto increment?
if you mean assigning values on runtime here is the code.
#include <iostream>
using namespace std;
int main()
{
int value;
int arr[15][15];
for(int row=0; row<15;row++)
{
for(int col=0; col<15;col++)
{
cin>>value;
arr[row][col] =value;
}
}
int row=0;
while(row<15)
{ for(int col=0; col<15;col++)
{
cout<<arr[row][col];
}
cout<<endl;
row++;
}
return 0;
}
If you mean assigning value by auto increment
#include <iostream>
using namespace std;
int main()
{
int value=0; //value start at 0
int arr[15][15];
for(int row=0; row<15;row++)
{
for(int col=0; col<15;col++)
{
arr[row][col] =value;
value++;
}
}
int row=0;
while(row<15)
{ for(int col=0; col<15;col++)
{
cout<<arr[row][col];
}
cout<<endl;
row++;
}
return 0;
}
Hope this helps.
+ 2
if you want an all even values just replace the value with value++ in the line arr[row][col] = value;
so the for loop sratement should be
{arr[row][col] = value++;
value++;}
and if you want an odd values replace the starting value to 1.
+ 2
if you want an all even values just replace the value with value++ in the line arr[row][col] = value;
so the for loop sratement should be
{arr[row][col] = value++;
value++;}
and if you want an odd values replace the starting value to 1.
0
thanks, I Mean the second one
0
then how can we put the odd and even number from incrementation value I mean auto number but after reversing
0
thanks for your help
l appreciate