Tuesday, 16 August 2016

Powers with recursive function

This code takes two variables and then powers the second one to the first. For example...

Enter your variable or type end to break:
5
Enter your power:
3
125
Type any key to continue
..........................................................................................


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

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

            power();   
                }

        private static void power()
        {
            while (1 == 1)
            {

                Console.WriteLine("");

                Console.WriteLine("Enter your variable or type end to break: ");
                string b = Console.ReadLine();

                if (b == "end")
               
                    break;


                int x = int.Parse(b);


                Console.WriteLine("Enter your power: ");
                int y = int.Parse(Console.ReadLine());

                Console.WriteLine(Power(x, y));
                Console.WriteLine("Type any key to continue");
                Console.WriteLine("..................................................");
                string a = Console.ReadLine();
            }

        }
             public static int Power(int x, int y)
        {
            if (y == 0)
                return 1;
            else
                return x * Power(x, y - 1);
        }


    }
}




Powers with a for loop

This C# code takes 2 variables and then powers the second variable to the first. For example...

Enter your variable:
5
Enter your power:
3
125



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

namespace Powers
{
    class Program
    {
        static void Main(string[] args)
        {
            power();
        }

        private static void power()
        {
            while (1 == 1)
            {
                Console.WriteLine("Enter your variable: ");
                double x = double.Parse(Console.ReadLine());

                Console.WriteLine("Enter your power: ");
                double y = double.Parse(Console.ReadLine());

                double z = x;
                for (int i = 1; i < y; i++)
                {
                    z = x * z;
                }

                Console.WriteLine(z);
                string a = Console.ReadLine();
            }
        }
    }
}



Friday, 12 August 2016

Your first Raspberry Pi 2/3 project in C# from start to finish in 5 easy steps

1) Download Visual Studio Enterprise edition for free at https://www.visualstudio.com/

2) Download Windows 10 IoT Dashboard onto your PC at Download Dashboard. Download Windows 10 IoT onto your Pi from https://developer.microsoft.com/en-us/windows/iot/GetStarted

3) follow these instructions to set up the components for this project on your Pi correctly https://developer.microsoft.com/en-us/windows/iot/samples/helloblinky

4) Click here download many samples of C# code for Raspberry Pi. Once you have extracted the contents of the zip file open the folder 'Blinky' and then open the folder 'CS' (meaning CSharp). Now open the Blinky.sln file and this should take you to Visual Studio. If the code does not open automatically, click on 'MainPage.xaml' in the menu on the right hand side and then 'MainPage.xaml.cs'. Now that your code is open make sure that you have the right settings to deploy code onto your Raspberry Pi. In the toolbar at the top, in the second white box, make sure that the 'ARM' setting is on, not the 'x64' or the 'x86' which will not work for the Raspberry Pi. Next to this, open the drop down menu for the green play sign and select 'Remote Machine' not 'Device'.

5) Just run your code by clicking the green play button in the toolbar at the top. It may take a little time to deploy.

You have finished your first Raspberry Pi Project!