11th program Console Application
1.Binary To Decimal Conversion
Source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace con11th
{
class Program
{
static void Main(string[] args)
{
int num, binary_val, decimal_val = 0, base_val = 1, rem;
Console.Write("Enter a Binary Number(1s and 0s) : ");
num = int.Parse(Console.ReadLine()); /* maximum five digits */
binary_val = num;
while (num > 0)
{
rem = num % 10;
decimal_val = decimal_val + rem * base_val;
num = num / 10;
base_val = base_val * 2;
}
Console.Write("The Binary Number is : " + binary_val);
Console.Write("\nIts Decimal Equivalent is : " + decimal_val);
Console.ReadLine();
}
}
}
2.Decimal To Binary
Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _11th_con_dtob
{
class Program
{
static void Main(string[] args)
{
int n, i;
int[] a = new int[10];
Console.Write("Enter the number to convert: ");
n = int.Parse(Console.ReadLine());
for (i = 0; n > 0; i++)
{
a[i] = n % 2; n = n / 2;
}
Console.Write("Binary of the given number= ");
for (i = i - 1; i >= 0; i--)
{
Console.Write(a[i]);
}
Console.ReadLine();
}
}
}
3.Decimal To Octal Conversion
Source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _11th_con_dtoo
{
class Program
{
static void Main(string[] args)
{
int decimalNumber, quotient, i = 1, j;
int[] octalNumber = new int[100];
Console.Write("Enter a Decimal Number :");
decimalNumber = int.Parse(Console.ReadLine());
quotient = decimalNumber;
while (quotient != 0)
{
octalNumber[i++] = quotient % 8;
quotient = quotient / 8;
}
Console.Write("Equivalent Octal Number is: ");
for (j = i - 1; j > 0; j--)
{
Console.Write(octalNumber[j]);
}
Console.Read();
}
}
}
12th Program Console Application
Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _12th_con_app
{
class Program
{
static void Main(string[] args)
{
while (true)
{
int ranno = Newnum(1, 101); int count = 1;
while (true)
{
Console.Write("Enter a number between 1 and 100(0 to quit):");
int input = Convert.ToInt32(Console.ReadLine());
if (input == 0) return;
else if (input < ranno)
{
Console.WriteLine("Low, try again.");
++count;
continue;
}
else if (input > ranno)
{
Console.WriteLine("High, try again.");
++count;
continue;
}
else
{
Console.WriteLine("You guessed it! The number was {0}!", ranno);
Console.WriteLine("It took you {0} {1}.\n", count, count == 1 ?
"try" : "tries");
break;
}
}
}
}
static int Newnum(int min, int max)
{
Random random = new Random(); return random.Next(min, max);
}
}
}