You are on page 1of 3

Write a program to swap to nos. using XOR operation.

using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace @switch
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter first no.");
int a=int.Parse(Console.ReadLine());
Console.WriteLine("Enter second no.");
int b=int.Parse(Console.ReadLine());
int result;
result=a^b;
a=a^result;
b=b^result;
Console.WriteLine("The no. after swapping is:\n a={0}\n b={1}",a,b);
Console.ReadLine();
}
}
}
Output

Write PROGRAM to chec k whether a no. is Armstrong or not.


using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace armstrong
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the no.");

int num = int.Parse(Console.ReadLine());


int n=num;
int res=0;
int r, q;
while (n != 0)
{
q = n / 10;
r = n % 10;
r = r * r * r;
res =res+ r;
n = q;
}
if (res == num)
Console.WriteLine("Number is armstrong");
else
Console.WriteLine("No. is not an armstrong");
Console.ReadLine();
}

Output:

Program to print pascal triangle.


using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace paascal
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 4; i++)
{
for (int j = 4 - i; j >= 0; j--)
Console.Write(" ");
int num = (int)Math.Pow(11, i);
int q;int r,rem=0;
while (num != 0)
{
q = num / 10;
r = num % 10;

rem = rem*10+ r;
num = q;
}
num=rem;
while (num != 0)
{
q = num / 10;
r = num % 10;
Console.Write(r);
Console.Write(" ");
num = q;
}

Console.WriteLine();

}
}

}
Console.ReadLine();

Output

You might also like