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!

Wednesday, 27 July 2016

Giving Change

Create a C# program to return the change of a purchase, using coins (or bills) as large as possible. Assume we have an unlimited amount of coins (or bills) of 100, 50, 20, 10, 5, 2 and 1, and there are no decimal places. Thus, the execution could be something like this:
Enter the price
44
Enter the money given
100
Your change is 56
Number of 50s returned is 1
Number of 5s returned is 1
Number of 1s returned is 1



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

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

            Console.WriteLine("Enter the price");
            int price = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter the money given");
            int moneyGiven = int.Parse(Console.ReadLine());

            int change = moneyGiven - price;
            string message = "Your change is " + change + "\n";
            int fifty = 0;
            int twenty = 0;
            int ten = 0;
            int five = 0;
            int two = 0;
            int one = 0;

            string msg50 = "";
            string msg20 = "";
            string msg10 = "";
            string msg5 = "";
            string msg2 = "";
            string msg1 = "";

            while (change > 0)
            {
                if (change >= 50)
                { change -= 50;
                    fifty += 1;
                    msg50 = "Number of 50s returned is " + fifty + "\n";
                }
                if (change >= 20)
                {
                    change -= 20;
                    twenty += 1;
                    msg20 = "Number of 20s returned is " + twenty + "\n";
                }
                if (change >= 10)
                {
                    change -= 10;
                    ten += 1;
                    msg10 = "Number of 10s returned is " + ten + "\n";
                }
                if (change >= 5)
                {
                    change -= 5;
                    five += 1;
                    msg5 = "Number of 5s returned is " + five + "\n";
                }
                if (change >= 2)
                {
                    change -= 2;
                    two += 1;
                    msg2 = "Number of 2s returned is " + two + "\n";
                }
                if (change == 1)
                {
                    change -= 1;
                    one += 1;
                    msg1 = "Number of 1s returned is " + one;
                }
            }

            string answer = message + msg50 + msg20 + msg10 + msg5 + msg2 + msg1;
            Console.WriteLine(answer);
            Console.Read();
        }
    }
}

Several Multiplication Tables

Display a range of multiplication tables, as long as the user asks for... The first input is the start of the range and the second number is the end. For example if you input 2 and then 6, the computer will display the multiplication tables of 2, 3, 4, 5 and 6. The third number represents how many numbers you want in each table. f\or example if you then put the third number as 7, the computer will display the tables from 2 to 6 and the table will go from 2x1 to 2x7 then move on to 3x1 etc.


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

namespace Multiplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your start point of the table ");
            int number = int.Parse(Console.ReadLine());
           
            Console.WriteLine("Enter your end point of the table  ");
            int  amount   = int.Parse(Console.ReadLine());

            Console.WriteLine("till what number each table to show");
            int length = int.Parse(Console.ReadLine());

            int n = number;
            int x = 1;
            int a = 1;

            while (number <= amount)
            {
                while ( x <= length)
                {
                    Console.WriteLine("{0} x {1} = {2}", number, x, x*number);
                   
                    x += 1;
                }

                number += 1;
                x = 1;

            }
            Console.ReadLine();
        }
    }
}


Wednesday, 30 March 2016

FLL 2015-16 Overview

Last year me and a group of friends decided to enter into a Robotics Competition called FLL. In total we were allowed to have ten people maximum but we couldn't get enough people so had to make do with just 6. We did put it off until the last few weeks, and in the end we realised that our robot was inconsistent, and we hadn't even started making a presentation for the theme - Trash. So in the last 2 weeks we made an entirely new robot and made our presentation. We did quite well on the day itself as we came 3rd in the Robot Challenge and won the award for best presentation and idea! We were really proud as were up against only schools, and were 1 of the 2 teams that were doing it for the first time, out of 14 total teams. Something we really struggled doing was getting everyone together, as weren't doing this as a school and we all had different extra-curricular activities and hobbies, even though we were all from the same school, apart from one. A really great thing is that even though we didn't have a single practice as a whole team, and 2 of the team members had never even met before the day of the real thing, I think we all got along well together and we had a really good team chemistry. Out of 6 of us, only 2 of us had ever used Lego Mindstorms before and done the programming with it, so we really had to play to everyone's strengths, especially in the short time that we were left with. Our team name was RY8 consisting of me - Aadi, Rayaan, Shashank, Aporv, Leo and Ayush and we will definitely be doing this again this year.

Wednesday, 4 February 2015

Match It!

'Match It!' is a version of 'Snap'. You have 35 seconds to match all the cards with their pairs - 8 pairs, 16 cards. Great sound and animations. Download on IOS now!