WAP for simple calculator using switch case
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace switch_case
{
class Program
{
static void Main(string[] args)
{
int a, b, ch,
add, div, mul, sub;
Console.Write("Enter
the 1st no=");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter
the 2nd no=");
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("1.Addition");
Console.WriteLine("2.Subtraction");
Console.WriteLine("3.Multiplication");
Console.WriteLine("4.Division");
Console.Write("Enter your choice");
ch = Convert.ToInt32(Console.ReadLine());
switch (ch)
{
case 1:
add = a + b;
Console.WriteLine(add);
break;
case 2:
sub = a - b;
Console.WriteLine(sub);
break;
case 3:
mul = a * b;
Console.WriteLine(mul);
break;
case 4:
div = a / b;
Console.WriteLine(div);
break;
default :
Console.WriteLine("wrong
choice");
break;
}
Console.ReadLine();
}
}
}
OUTPUT:-
WAP for GCD of two numbers.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace vaishu
{
class Program
{
static int gcd(int a, int b)
{
int temp;
if (b == 0)
return a;
else
while (b != 0)
{
temp = b;
b = a % b;
a = temp;
}
return a;
}
static void Main(string[] args)
{
int n1, n2, gcd1;
Console.WriteLine("Enter
first number" );
n1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter
second number");
n2 = Convert.ToInt32(Console.ReadLine());
gcd1 = gcd(n1, n2);
Console.WriteLine("gcd=
" + gcd1);
Console.ReadLine();
}
}
}
Output:
WAP for fibonacci series
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace fib
{
class Program
{
static void Main(string[] args)
{
int f1 = 0, f2 = 1, f3 = 0;
int n,i;
Console.Write("Enter
the limit= ");
n = int.Parse(Console.ReadLine());
Console.WriteLine(f1);
Console.WriteLine(f2);
for (i =3; i <= n; i++)
{
f3 = f1 + f2;
f1 = f2;
f2 = f3;
Console.WriteLine(f3);
}
Console.ReadLine();
}
}
}
Output:
WAP for number is armstrong
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace arm
{
class Program
{
static void Main(string[] args)
{
int sum, temp, no, rem;
Console.WriteLine("Armstrong
no between 1 to 1000=");
for (no = 1; no <= 1000; no++)
{
temp = no;
sum = 0;
while (temp > 0)
{
rem = temp % 10;
sum = sum + (rem * rem * rem);
temp = temp / 10;
}
if (no == sum)
{
Console.WriteLine(" "
+ no);
}
}
Console.ReadLine();
}
}
}
Output:
WAP to swap without using third variable.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace temporary
{
class Program
{
static void Main(string[] args)
{
int a, b;
Console.WriteLine("Before
Swapping:- ");
Console.Write("\nEnter
the value of a= ");
a=Convert.ToInt32(Console.ReadLine());
Console.Write("\nEnter
the value of b= ");
b=Convert.ToInt32(Console.ReadLine());
a = a + b;
b = a - b;
a = a - b;
Console.WriteLine("
\n After Swapping:-\n");
Console.WriteLine("\nvalue
of a= "+a);
Console.WriteLine("\nvalue
of b= " + b);
Console.ReadLine();
}
}
}
OUTPUT:-
WAP to access and mutate named properties.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class Example
{
int _number;
public int Number
{
get
{
return this._number;
}
set
{
this._number=value;
}
}
}
class Program
{
static void Main(string[] args)
{
Example example=new
Example();
example.Number=5;//set()
Console.WriteLine("number="+example.Number);
Console.ReadLine();
}
}
}
OUTPUT:-
No comments:
Post a Comment