How To Code With Sharpdevelop - Finding If Random Number is odd or not and more #3

in #utopian-io8 years ago (edited)

What Will I Learn?

  • You will learn how to code in c# with sharpdevelop
  • You will learn using coding to solve all basic problems in real life.

Requirements

  • Basic knowledge of coding.
  • Basic knowledge of c#.
  • Basic knowledge of using loops and coding system.
  • Sharpdevelop

Difficulty

  • Basic

Tutorial Contents

Hello,in this tutorial we are about to get more deep into c#.I will show you how to use coding to make your life easier.In this tutorial we will focus on basic programs like a program that shows if the entered number is odd or even.After reading this tutorial you must understand how to use c# to solve basic daily problems.Let's get it started;

In this program we will ask user to enter a random number then we will make code to find if the number is odd or even.

As usual we have to define libraries to take codes from database.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

Then we will define class and specify that code is starting


namespace check1
class Program
static void Main(string[] args)

1.png

Defining integer,then asking user to enter a random number


int i;
Console.Write("Please enter a number: ");

Equalizing i integer to 32 byte.Int.parse is used for that.


i = int.Parse(Console.ReadLine());
if (i % 2 == 0)
Console.Write("Number is even");
Console.Read();

2.png

As you know If loop is used for possibility we have to add 'else' for other possibility.


else
Console.Write("Number is Odd.");
Console.Read();

3.png

Outputs of code;

4.png

Let's get to the other code;

In this example we are going to write a program that forms a one-sided triangle consisting of numbers 1 and 0 as many as the number of lines to be entered.Basically it will output us a vertical triangle.

Defining libraries as usual and naming our program


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

After defining our libraries and naming our program we define our integer,input and defining LastInt and equalizing it to zero to make it start from zero.


int p, lastInt = 0, input;

Asking user to enter the number of rows and converting input to the 32 byte.


Console.WriteLine("Enter the Number of Rows : ");
input = int.Parse(Console.ReadLine());

We use for loop because if user enter 6 for example,we have to make rows increase and for loop is best for that.


for (int i = 1; i <= input; i++)
for (p = 1; p <= i; p++)

After using for loops to increase lines step by step,we defined lastint to zero in begging and we check if lastint is 1 we make code write 0 if not we make it write 1.


if (lastInt == 1)
Console.Write("0");
lastInt = 0;
else if (lastInt == 0)
Console.Write("1");
lastInt = 1;
Console.Write("\n"); // this is for new line
Console.ReadLine();

5.png

Outputs ;

6.png

7.png

Curriculum

If you want to learn c# coding from zero these tutorials will help you to become good coder in c#.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

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

Thank you very much!

The contribution should not have been approved because the project has not been actually updated within the last year. There is only a commit fixing the headers in the readme file but no update with the code.

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

Unvoted for breaking the Utopian Rules https://utopian.io/rules

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.098
BTC 64053.69
ETH 1841.16
USDT 1.00
SBD 0.38