[go: up one dir, main page]

0% found this document useful (0 votes)
9 views3 pages

11th and 12th Program Console Application

The document contains source code for three console applications: converting binary to decimal, decimal to binary, and decimal to octal. Additionally, it includes a number guessing game where the user tries to guess a randomly generated number between 1 and 100. Each application is implemented in C# and demonstrates basic programming concepts such as loops and conditionals.

Uploaded by

hunter225113220
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

11th and 12th Program Console Application

The document contains source code for three console applications: converting binary to decimal, decimal to binary, and decimal to octal. Additionally, it includes a number guessing game where the user tries to guess a randomly generated number between 1 and 100. Each application is implemented in C# and demonstrates basic programming concepts such as loops and conditionals.

Uploaded by

hunter225113220
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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);
}
}
}

You might also like