What Will I Learn?
Hello,in this tutorial;
- You will learn how to use for loop properly.
- You will learn how to code with c#
- You will learn Sharpdevelop
Requirements
- Sharpdevelop
- Basic knowledge of c# coding.
- Basic knowledge of using sharpdevelop
Difficulty
- Basic
Tutorial Contents
Hello,in this tutorial i am going to show you how to use for loop properly to make hard math problems look easy.This program will calculate any factorial easily.Then i will show how to make it backwards with c#.Let's get it started;
As usual we define our library to make codes work.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Calculate_Factorial
class Program
static void Main(string[] args)
We define our integers,first we define "n" as math term.Then we define "Result" as double.
int n;
double Result = 1;
In this part we print "n".Then convert it to int 32byte.
Console.Write("n=");
n = int.Parse(Console.ReadLine());
Now we gotta use for loop to increase our variable if needed."Result *=i" this line is how you do the factorial problem.This how you do it on c#
for (int i = 1; i <= n; i++)
Result *= i;
Finally we gotta make console to write the line then make the factorial math in c# type.Then do the addition on result.
Console.WriteLine();
Console.Write(n + "!=" + Result);
Console.ReadKey();
Output of this code ;
Now we make it reverse.First define libraries.Name our program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Reverse_Factorial
class Program
static void Main(string[] args)
Now we define two integers because we need to integers both for "if" loop.
int n;
int k=1;
We ask user to enter the value then convert "n" to integer 32byte.
Console.Write("Enter The Value Please=");
n = int.Parse(Console.ReadLine());
Now in this line i will use for loop to calculate what user have entered.I did it 90.000 but you can make it bigger if you want.This part is important ;
for (int i = 1; i < 90000; i++)
k = k * i;
Now we will evaluate the possibility and use "if" loop for that.We calculate the factorial in backwards in second line.
if (k==n)
Console.WriteLine(n+"="+i+"!");
break;
Now if user enters a number that is not a factorial we have to tell it to the user.This part is where we do it;
else if (k>n)
Console.WriteLine("The number you have entered is not factorial!");
break;
Console.ReadKey();
Outputs of the code;
Curriculum
If you want to start from somewhere in c# coding keep up with me.More to come...
From first to last
https://steemit.com/utopian-io/@milliar/how-to-convert-mm-to-any-length-in-sharpdevelop
https://steemit.com/utopian-io/@milliar/how-to-use-datetime-method-on-sharpdevelop-4
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @arie.steem, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
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 headings in the readme file but no update with the code.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
@milliar, Upvote is the only thing I can support you.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit