Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace kertotaulu
- {
- class kertotaulu
- {
- public static void Main(string[] args)
- {
- int rivi, sarake;
- while (true)
- {
- LueRivitJaSarakkeet(out rivi, out sarake);
- TulostaTaulukko(LuoTaulukko(rivi, sarake));
- }
- }
- public static void LueRivitJaSarakkeet(out int rivi, out int sarake)
- {
- bool huijaabottia = false;
- Console.WriteLine("Anna taulun rivien määrä: ");
- bool success = int.TryParse(Console.ReadLine(), out rivi);
- if (!success || rivi <= 0)
- {
- huijaabottia = true;
- }
- Console.WriteLine("Anna taulun sarakkeiden määrä: ");
- success = int.TryParse(Console.ReadLine(), out sarake);
- if (!success || sarake <= 0)
- {
- huijaabottia = true;
- }
- if(huijaabottia)
- System.Environment.Exit(1);
- Console.Write("\n");
- }
- public static int[,] LuoTaulukko(int rivi, int sarake)
- {
- int[,] taulu = new int[rivi, sarake];
- for (int r = 0; r < taulu.GetLength(0); r++)
- {
- for (int s = 0; s < taulu.GetLength(1); s++)
- {
- taulu[r, s] = (r + 1) * (s + 1);
- }
- }
- return taulu;
- }
- public static void TulostaTaulukko(int[,] taulukko)
- {
- int sarake = 1, rivi = 1;
- // Console.Write(" ");
- while(sarake <= taulukko.GetLength(1))
- {
- Console.Write("{0} ", sarake);
- sarake++;
- }
- Console.Write("\n");
- Console.Write("\n");
- for (int r = 0; r < taulukko.GetLength(0); r++)
- {
- Console.Write("{0} ", rivi);
- rivi++;
- for (int s = 0; s < taulukko.GetLength(1); s++)
- {
- Console.Write("{0} ", taulukko[r, s]);
- }
- Console.Write("\n");
- }
- Console.Write("\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement