Thursday, 8 April 2010
Wednesday, 17 March 2010
A Simple FeedForward Three Input Perceptron(Neural Network) using C#
Simple Perceptron with binary classifier using C#
The following code is a simple three input perceptron neural network with a binary classifier using c#.This neural net was the most primitive invented by Rosenblatt in 1959.
// A simple three input Perceptron Model using C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class perceptrontest1
{
static void elements()
{
//intialization of inputs and weights for nueral net//
decimal x1, x2, x3, w1, w2, w3;
decimal isum,thresh;
// bias input to neural net//
int bias=1;
// Provide userdefined inputs and weights//
Console.WriteLine("enter the inputs to be feeded in perceptron");
x1 = Convert.ToDecimal(Console.ReadLine());
x2 = Convert.ToDecimal(Console.ReadLine());
x3 = Convert.ToDecimal(Console.ReadLine());
Console.WriteLine("enter the value of the weights");
w1 = Convert.ToDecimal(Console.ReadLine());
w2 = Convert.ToDecimal(Console.ReadLine());
w3 = Convert.ToDecimal(Console.ReadLine());
// calculation of sum//
Console.WriteLine("calculating");
isum = (x1 * w1 + x2 * w2 + x3 * w3)+bias;
Console.WriteLine("The summed output is:{0} ",isum);
Console.WriteLine("enter the desired threshold value");
thresh = Convert.ToDecimal(Console.ReadLine());
// Binary classifier//
if (isum > thresh)
{
int y = 0;
Console.WriteLine("your classification is:{0}",y);
}
else if (isum < thresh)
{
int y = 1;
Console.WriteLine("your classification is:{0}",y);
}
}
static void Main(string[] args)
{
elements();
}
}
}
Sunday, 7 March 2010
Simple Arithmetic Calculator using C#
Simple Arithmetic calculator in C# using Switch case
The following is the code for creating a simple arithmetic calculator using switch case:what is a switch case?
- Switch case helps the programmer to provide multiple conditions when multiple options are required to be provided
Syntax:
switch(variablename)
{
case expression1:
statement;
break;
case expression2:
statement;
break;
.
.
.
default:
statement;
break;
}
The Program for simple arithmetic calculator is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class maths
{
static void Main(string[] args)
{
// float datatype chosen for decimal calculation.
float a, b;
// character datatype chosen to provide option for-
// switch case.
char option;
Console.WriteLine("Enter the numbers to be calculated");
// first value to be provided by the programmer.
a = Convert.ToInt32(Console.ReadLine());
// second value to be provided by the programmer.
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the option");
Console.WriteLine("Enter a to add");
Console.WriteLine("Enter b to subtract");
Console.WriteLine("Enter c to multiply");
Console.WriteLine("Enter d to Divide");
// option to be inserted by the programmer.
option = Convert.ToChar(Console.ReadLine());
// switch case
switch (option)
{
// various options of switchcase(a,b,c,d)
case 'a':
Console.WriteLine("the sum is{0}:", a + b);
break;
case 'b':
Console.WriteLine("the difference is{0}:", b - a);
break;
case 'c':
Console.WriteLine("the product is{0}:", a * b);
break;
case 'd':
Console.WriteLine("the divided output is {0}:", a / b);
break;
// default option.
default:
Console.WriteLine("invalid choice");
break;
}
}
}
}
Download Site- Visual Studio Express
Download Site- Visual Studio Express
If you are a developer in seek of free visual studio software to compose your codes then Visual Studio Express Edition is your best friend,Express edition can be downloaded free from the Microsoft Website,The weblink is as follows:
Download it from the webpage above and follow instructions on the webpage and on the installer while downloading and installing the software on your webpage.
Simple C# - Add Two Numbers and Print out its Sum
C# Code-Add Two Numbers and Print out its Sum
The following is the code using C# to Add two numbers and print out its Sum,The code below consists of integer(int) data type with values specified.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class sum
{
static void Main(string[] args)
{
// defining the datatype int a and int b.
int a = 5;// datatype int a(integer) with value 5.
int b = 3;// similarly int b(integer) with value 3.
// now addition of a and b and printing out its sum.
Console.WriteLine("The Sum Is :{0}", a + b);
}
}
}
But if the programmer wishes to input values of his own or technical term userdefined values the code is as follows.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class sum
{
static void Main(string[] args)
{
int a, b;
Console.WriteLine(" Enter the values to be added");
// provide user defined inputs
a=Convert.ToInt32(Console.ReadLine());
b=Convert.ToInt32(Console.ReadLine());
// print out the sum
Console.WriteLine("The Sum Is :{0}", a + b);
}
}
}
similarly other mathematical operations can be performed ,eg: subtraction,multiplication etc.
A simple C# program for Beginners-Hello World
The Following program is for people who have just started learning C# .
Thats it...you just created your very first application using C#.
C# program for Beginners-Hello World
- To create your first application , Open Visual studio 2008 or Visual C# Express edition.
- In Visual studio select C# from the Menu and select Console Application.
- Next in solution explorer on the right hand corner(if not visible click on view from the menu bar at the top and select solution explorer)rightclick on the program.cs file and rename it to helloworld.cs(it will pop up a message ,just press enter/return key)
- you ll see the name of the class changes to helloworld (highlited in lighter shade of blue color).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class helloworld // name of the class
{
static void Main(string[] args)// main method with void return type
{
Console.WriteLine(" Hello World");// print out the statement on command prompt.
}
}
}
Now Press key F6 to Compile /build the code or use mouse to click on build from the menu bar at the top.
Now Press Key Ctrl+F5 to see the output or choose option Debug from menu bar and click on start without debugging option.
Thats it...you just created your very first application using C#.
Friday, 5 March 2010
Simple C# Code to Arrange arrays in Descending and Ascending Order.
// The Following Code arranges the Single-Dimensional Array in Descending Order.
// hope this helps you all.
}
C# Code to Arrange arrays in Descending and Ascending Order.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class descend
{
static void Main(string[] args)
{
int[] num1 = new int[5] { 55,2,90,45,7};// Array Defined of 5 elements.
Array.Sort(num1); //Sorts the Array first.
Array.Reverse(num1);//Reverses the Array
foreach (int i in num1)// Loop applied for each element in the array
{
Console.WriteLine(i);// Output Is Displayed
}
}
}
// To Arrange the array in Ascending order the code is given below;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Ascend
{
static void Main(string[] args)
{
int[] num1 = new int[5] { 55,2,90,45,7};
Array.Sort(num1);
foreach (int i in num1)
{
Console.WriteLine(i);
}
}
}
}
Its the same as the code for arranging arrays in descending order ...except "Array.Reverse()" has been excluded from the code
.// hope this helps you all.
}
Labels:
.Net,
Arrays C#,
c#,
C#.Net,
Console Application in C#,
Dot Net,
Visual Studio
Subscribe to:
Posts (Atom)