Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Zad1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.             FormatowanieTablicy();
  19.             Losowanko();
  20.         }
  21.  
  22.         int N; // Wymiar tablicy
  23.  
  24.         private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  25.         {
  26.             FormatowanieTablicy();
  27.             Losowanko();
  28.         }
  29.  
  30.         public void FormatowanieTablicy()
  31.         {
  32.             N = (int)numericUpDown1.Value;
  33.             // Formatowanie macierzy
  34.             dataGridView1.RowCount = N;
  35.             dataGridView1.ColumnCount = N;
  36.  
  37.             dataGridView2.RowCount = N;
  38.             dataGridView2.ColumnCount = 1;
  39.  
  40.             dataGridView3.RowCount = N;
  41.             dataGridView3.ColumnCount = 1;
  42.         }
  43.  
  44.         public void Losowanko()
  45.         {
  46.             Random los = new Random();
  47.             double losik;
  48.             for (int j = 0; j < N; j++)
  49.             {
  50.                 for (int i = 0; i < N; i++)
  51.                 {
  52.                     losik = los.Next(-100, 100) + los.NextDouble();
  53.                     dataGridView3[0, i].Value = losik.ToString("0.00");
  54.                     losik = los.Next(-100, 100) + los.NextDouble(); // Dodałem
  55.                     dataGridView1[j, i].Value = losik.ToString("0.00");
  56.                 }
  57.             }
  58.         }
  59.         private void Losuj_Click(object sender, EventArgs e)
  60.         {
  61.             Losowanko();
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement