Writing C# programs-easy-

Elie
by Elie · 11 posts
14 years ago in .Net (C#, VB, etc)
Posted 14 years ago · Author
well im not posting this to get the solution, I already have it .
im posting this assignment to make interacting between the members of this site and also to give benefits to those whom wants to learn C# but they dont know much about it .
( sure I hope that Don approve to post things like these, if not its ok :) )

so lets start with a very simple program :

Using C# Write a program that calculate the factorial of a number N,
then improve it to estimates the value of the mathematical constant e by using the formula :

e = 1 + 1/1! + 1/2! + 1/3! ..........................

1! = factorial of 1, 2! = factorial of 2 ..........................................
any ideas ?? :)
Posted 14 years ago · Author
OOPS lol , I think that no one is interested into c#
anyway I'll post the solution .
Code
using System;
using System.Collections.Generic;
using System.Text;
namespace Factorial
{
    class Program
    {
        static void Main(string[] args)
        {
            int N;
            long fact = 1;

            // input the number
            Console.WriteLine("Enter a Number");
            N = Convert.ToInt32(Console.ReadLine());

            // calculate the factorial
            for (int i = 2; i <= N; i++)
            {
                fact *= i;
            }

            // output the result
            Console.WriteLine("The Result is {0}", fact);
        }
    }
}
Posted 14 years ago · Author
then we could easily improve it to calculate the ( e ) by doing this
Code

using System;
using System.Collections.Generic;
using System.Text;
namespace Factorial
{
    class Program
    {
        static void Main(string[] args)
        {
           Console.WriteLine("This program is to calculate the natural logarithm ( e )");
           double fractional=1;
           double e=2;
           /* in the next step ( 100 ) is optional , but you should make the 
reapitition over 17 times to get an accurate value of (e) */

           for (int i = 2; i <=100; i++)
           {
              fractional = fractional * i;
              e = e + (1 / fractional);
           }
           Console.WriteLine(" e is {0}", e);
   
       
        }
    }
}

PST. ( e ) should look something like this 2.71828182845905
Posted 14 years ago
I dunno c# but I can give u c
Posted 14 years ago
Don Von Free Credits wrote:
JonXRulz wrote:
I dunno c# but I can give u c


C# is microsoft's version of C++, which is just C without pointers and String support added.


yeah but the statements are kinda different
Posted 14 years ago
Thanks this really helped me out too :)
Posted 14 years ago
hello :D
Posted 13 years ago
Helpful:)
Posted 13 years ago
Useful

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT
Select a forum Protection     Help & Support     Introductions     Mafia News     IMVU News General Discussion     IMVU Lounge        IMVU Series / Roleplaying        Social Games     Mafia Market     Mafia Tools        Premium IMVU Tools        Off Topic Tools     Off Topic     Contests Creator Corner     Graphics Design        Photoshop        GIMP     Basic Creator Help     Catalog And Product Showcase     3D Meshing        3Ds Max        Sketchup        Blender Gangsters with Connections     White Hat Activities        Google Hacking        Trackers Programming Corner     Coding        Python        .Net (C#, VB, etc)        Flash        JAVA        Autoit        Batch        HTML & CSS        Javascript        PHP        Other        IMVU Homepage Codes           General           About me Panel           Messages Panel           Special Someone Panel           Visitors Panel           New Products Panel           Rankings Panel           Wishlist Panel           My Badges Panel           Outfits Panel           Url Panel           Groups Panel           Slideshow Panel           My Room Panel           Sandbox panel           Layouts     Help & Requests Free Credits     Approved Methods     Submit Methods Free Money     Approved Methods     Submit Methods Adult Corner     Get Mafia AP Here     AP Lounge        AP Social Games        Casual Dating Tips     IMVU Slave Market & Escorts