ဒီတစ္ပုဒ္ကေတာ့ -10 ကေန 10 ၾကားကို Random ေခါက္ခိုင္းတာပါခင္ဗ်။
rand()%20 က 0 ကေန 20 ထိၾကားကို ထုတ္ေပးမွာျဖစ္ပါတယ္။ သူ႔ကို 10 ႏႈတ္လိုက္တဲ့အခါမွာေတာ့ -10 to 10 ျဖစ္သြားပါေရာခင္ဗ်ာ။
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
void main()
{
int m,a[100][100];
cout<<"Enter the number of Row of square Matrix =\t";
cin>>m;
for (int i=0;i<m;i++)
for (int j=0;j<m;j++)
{
a[i][j]=rand()%10;
if ((i%2==0)&&(j%2==0)||(i%2!=0)&&(j%2!=0))
{
a[i][j]=a[i][j]*2;
}
else
a[i][j]=a[i][j]*2-1;
}
for (int i=0;i<m;i++)
{
cout<<'\n';
for (int j=0;j<m;j++)
{
cout<<a[i][j]<<" \t";
}
}
getch ();
}
အေျဖကေတာ့
Comments :
Post a Comment