4 תשובות
התגעגעתי ל c#..
אם אתה עדיין צריך
אכתוב לך
שואל השאלה:
אשמח שתכתוב לי
א
static private bool luckycell (int () arr, int row, int col)
(
int r = arr.getlength (0);
int c = arr.getlength (1);
int sumr = 0;
int sumc = 0;
for (int i = 0; i < r; i++)
(
sumc += arr (i, col);
)
for (int i = 0; i < c; i++)
(
sumr += arr (row, i);
)
if (sumc == sumr)
return true;
return false;
)
ב
using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading.tasks;

namespace consoleapplication1
(
class program
(
static private int () fillarr (int () arr) //filling an array with random numbers
(
const int min = 0;
const int max = 30;
int r = arr.getlength (0);
int c = arr.getlength (1);

random rand = new random ();
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
(
int s = rand.next (min, max);//random number between 0-30
arr (i, j) = s;
)
return arr;
)

static private void whortheluckycells (int () arr) //finding all the lucky cells
(
int r = arr.getlength (0);
int c = arr.getlength (1);
int sum = 0;
int counter = 0;
string str = "";
int () rows = new int (r); //array for rows sums
int () cols = new int (c); //array for columns sums
for (int i = 0; i < r; i++, sum = 0) //rows
(
for (int j = 0; j < c; j++)
(
sum += arr (i, j);
)
rows (i) = sum;
)
for (int k = 0; k < c; k++, sum = 0) //columns
(
for (int l = 0; l < r; l++)
(
sum += arr (l, k);
)
cols (k) = sum;
)
for (int i = 0; i < r; i++) //going through the arrays to find lucky cells
(
for (int j = 0; j < c; j++)
if (rows (i) == cols (j)) //if a row is equal to a column
(
str += arr (i, j) + "\t";
counter++;
)
)
if (counter == 1)
(
console.writeline ("there is " + counter + " lucky cell, its value is:");
console.writeline (str);
)
else if (counter!= 0)
(
console.writeline ("there are " + counter + " lucky cells, their values are:");
console.writeline (str);
)
else
console.writeline ("there are no lucky cells...");
)

static void main (string () args)
(
const int rowsnum = 20;
const int columnsnum = 20;
int () arr = new int (rowsnum, columnsnum);

whortheluckycells (fillarr (arr));
)
)
)
ממ סטיפס לא נותן לכתוב תוכנית נורמאלי..
מנסה בפרטי