Random Matrix Generator Using Sharpdevelop On C# [ Course 1]

in #utopian-io7 years ago (edited)

What Will I Learn?

Hello,i am starting a c# curriculum for you to learn a coding language which used for many area in software sector.I have been coding since 2009 and improvments of technology is insane over the years.In thse tutorials i will show you how to use c# to build programs that you wanted such as game,application for companies and more.In this tutorial;

  • You will learn how to use loops properly on c#
  • You will learn using sharpdevelop to do software
  • You will learn usage of math in c#

Requirements

  • Sharpdevelop
  • Basic knowledge of coding
  • Basic knowledge of using c# and sharpdevelop

Difficulty

  • Basic

Tutorial Contents

In this tutorial i am going to show you few examples in c# language such as random matrix generator and more.Let's get started to the coding;

Defining c# libraries and naming my program.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program class Program static void Main(string[] args)

Then i am asking user to enter matrixs row and column number.While i am doing it i define two integers "m","n" and converting them to 32 byte.

Console.Write("Enter matrix row number: "); int m = int.Parse(Console.ReadLine()); Console.Write("Enter matrix column number: "); int n = int.Parse(Console.ReadLine());

Now i am going to define a new array.My array will be integer because we ask user to enter numbers.Make arrays write whatever user enters.

int[,] A = new int[m, n]; int[,] B = new int[n, m];

In this part i am going to use "random" variable to make computer generate random numbers for my matrix."random" variable will generate as much as user wants.

Random r = new Random();

Now i am going to use for loop in for loop.I'm doing this because we want to generate on row and column."Next" variable returns non negative random integer that is less than the specified number.

for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) A[i, j] = r.Next(10); B[j, i] = A[i, j]; Console.WriteLine();

1.png

In the final step we will use double for loop again to make our array write our numbers on the screen.

for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) Console.Write(A[i, j] + " "); Console.WriteLine(); Console.ReadKey();

2.png

Outputs of the code

4.png

3.png

Now in this program i will make a simple program which shows me if i passed from my class or i have to try one more semester.In my college you must have atleast 60 over 100 so i will make a program that shows us if i passed from class when i enter my quiz notes.

I'm defining 3 integers which based on 3 quiz in one semester then asking user to enter 3 quiz grades below then make console read what user have entered.

int q1, q2, q3; Console.Write("1.Quiz Grade:"); q1 = Convert.ToInt16(Console.ReadLine()); Console.Write("2.Quiz Grade:"); q2 = Convert.ToInt16(Console.ReadLine()); Console.Write("3.Quiz Grade:"); q3 = Convert.ToInt16(Console.ReadLine());

Then i am defining a new integer called "avg" and equalizing it to calculate 3 quiz's average.We calculated average then we make console to write our average."avg.tostring" used for to convert avg integer to the string type.

int avg = (q1 + q2 + q3) / 3; Console.WriteLine("Average = " + avg.ToString());

5.png

Now if users average grade is bigger than 60 user will get a message "you passed" if not "try another semester" for doing this i am using if-else loop.

if (avg > 60) Console.WriteLine("You Passed class..."); // else Console.WriteLine("Try another Semester..."); // Console.ReadLine();

6.png

Output of the code

7.png

In the next tutorial i am going to make a electronic menu for a resturant.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved because it does not follow the Utopian Rules.

Hi, there are a few things wrong with your contribution

  • drewie13/Sharpdevelop is your own repository, and simply a fork of icsharpcode/SharpDevelop. This repository hasn't been updated in over a year (except the README), and so is not a valid repository. Just changing a few files slightly and committing them doesn't circumvent this rule and it feels very dishonest.
  • C# is copyright of Microsoft, thus it cannot be considered an open-source project that you can contribute to on Utopian.io.

For future tutorials I recommend that you find an open-source project you can contribute to that has been updated less than a year ago, and link this as the repository instead of your own fork. Also you should consider working on your formatting (use ``` above and below code blocks) and improving your spelling/grammar.

You can contact us on Discord.
[utopian-moderator]