// Write a program to print the binary format of a number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int num;
Console.Write("Enter a Number : ");
num = int.Parse(Console.ReadLine());
int quot;
string rem = "";
while (num >= 1)
{
quot = num / 2;
rem += (num % 2).ToString();
num = quot;
}
// Reversing the value
string bin = "";
for (int i = rem.Length - 1; i >= 0; i--)
{
bin = bin + rem[i];
}
Console.WriteLine("The Binary format for given number is {0}", bin);
Console.Read();
}
}
}
Sunday, 10 February 2013
Methods in CSharp
//Using Methods(Example)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharpConsole
{
class Method_ex
{
//Non value returning method without parameter
public void Test1()
{
int m = 5;
for (int i = 1; i <= 10; i++)
Console.WriteLine("{0}*{1}={2}", m, i, m * i);
}
// Non value returning method with parameters
public void Test2(int m, int n)
{
for (int i = 1; i <= n; i++)
Console.WriteLine("{0}*{1}={2}", m, i, m * i);
}
//value returning method with out parameters
public string Test3() //Static action
{
string str = ("Hello Leena");
str = str.ToUpper();
return str;
}
//value returning method with parameters
public string Test4(string str)
{
str = str.ToUpper(); //Dynamic Action
return str;
}
static void Main(string[] args)
{
Method_ex m=new Method_ex();
//calling non-value returning methods
m.Test1();
m.Test2(7,20);
//Calling value returning methods
string str=m.Test3();
Console.WriteLine(str);
Console.WriteLine(m.Test4("leena"));
Console.ReadLine();
}
}
}
Friday, 8 February 2013
Watched Videos!!!
Today was a day with practicing some c# programs, some SQL queries and also i saw some videos on C# console application.
I found one very good link on C# windows programing which is given below
Videos of windows programming in C#
I found one very good link on C# windows programing which is given below
Videos of windows programming in C#
Jagged Array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace jagged_arrray
{
class Program
{
static void Main(string[] args)
{
int[][] arr = new int[4][];
arr[0] = new int[6];
arr[1] = new int[7];
arr[2] = new int[8];
arr[3] = new int[4];
// printing values of jagged array using nested for
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr[i].Length; j++)
Console.Write(arr[i][j] + "");
Console.WriteLine();
}
// assigning values of a jagged array using nested for
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr[i].Length; j++)
arr[i][j] = j + 1;
}
Console.ReadKey();
}
}
}
Two Dimentional Array
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TD_array
{
class td_array
{
static void Main(string[] args)
{
int[,] arr=new int[3,5];
// Can also initialize the values at the time of declaration
/*int[,] arr = {{11,12,13,14,15},
{21,22,23,24,25},
{31,32,33,34,35},
};*/
int x = 0;
//printing values of 2D array using foreach loop
foreach (int i in arr)
Console.Write(i + " ");
Console.WriteLine("\n");
//assigning values to 2D array using nested for
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
x = x + 5;
arr[i, j] = x;
}
}
//printing values of 2D array using nested for loop
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
Console.Write(arr[i, j] + " ");
Console.WriteLine();
Console.ReadKey();
}
}
}
}
Example using Array Class
/* Array class- It is a predefined class of base class libraries present
* under the System namespace that provides a set of members using which
* we can perform operations like Sorting, Reversing,Copying etc*/
//Example of Array class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SD_array2
{
class sd_array2
{
static void Main(string[] args)
{
//assining a value at the time of declaration
int[] arr = { 19, 23, 71, 93, 58, 37, 62, 87, 5, 49, 16, 8, 35, 2 };
for (int i = 0; i < arr.Length; i++)
Console.Write(arr[i] + " ");
Console.WriteLine();
{
Array.Sort(arr);
foreach (int i in arr) ;
Console.Write(i + " ");
Console.WriteLine();
Array.Reverse(arr);
foreach (int i in arr)
Console.Write(i+ " ");
Console.WriteLine();
int[] brr = new int[10];
Array.Copy(arr, brr, 5);
Console.Write(i + " ");
Console.WriteLine();
}
Console.ReadKey();
}
}
}
Arrays in C#.Net(Single Dimentional Array)
//
// Example of One dimentional array
// Example of Single dimentional array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SD_array
{
class sd_array
{
static void Main(string[] args)
{
int [] arr= new int[6];
int x=0;
//accessing values of an array using for loop
for(int i = 0; i <6 data-blogger-escaped-10="" data-blogger-escaped-accessing="" data-blogger-escaped-an="" data-blogger-escaped-arr="" data-blogger-escaped-array="" data-blogger-escaped-assigning="" data-blogger-escaped-console.readkey="" data-blogger-escaped-console.write="" data-blogger-escaped-console.writeline="" data-blogger-escaped-each="" data-blogger-escaped-for="" data-blogger-escaped-foreach="" data-blogger-escaped-i="" data-blogger-escaped-in="" data-blogger-escaped-int="" data-blogger-escaped-loop="" data-blogger-escaped-of="" data-blogger-escaped-pre="" data-blogger-escaped-to="" data-blogger-escaped-using="" data-blogger-escaped-values="" data-blogger-escaped-x="">
Subscribe to:
Posts (Atom)