You are on page 1of 5

5th Sem BCA-DOTNET LAB BCACsP5.

V SEM - BCA
Paper: BCACsP5.4: Dot NET LAB PRACTICAL
LAB MANUAL
1. Write a Program in C# to Check whether a number is Palindrome or not.
using System;
public class palindrome
{
public static void Main(String[ ]args)
{
int n,r,sum=0,temp;
Console.WriteLine("Enter the number");
n=int.Parse(Console.ReadLine( ));
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if (temp = = sum)
{
Console.WriteLine("Palindrome");
Console.ReadLine( );
}
else
{
Console.WriteLine(" Not Palindrome");
Console.ReadLine( );
}
}
}

Dept of Computer Science, SSCASCW, Tumakuru Page 1


5th Sem BCA-DOTNET LAB BCACsP5.4

2. Write a Program in C# to demonstrate Command line arguments processing.


using System;
class CommandLineArg
{
public static void Main(string [ ] args)
{
Console.WriteLine("Number of Command Line Arguments:\n " +args.Length);
Console.WriteLine("Command line arguments are:\t ");
for(int i=0; i<args.Length; i++)
{
Console.WriteLine(args[i]+ "\t");
}
Console.ReadLine( );
}
}

Dept of Computer Science, SSCASCW, Tumakuru Page 2


5th Sem BCA-DOTNET LAB BCACsP5.4

3. Write a Program in C# to find the roots of Quadratic Equation.


using System;
class QuadEquation
{
public static void Main(string[ ] args)
{
double a,b,c;
double d,x1,x2;
Console.WriteLine("Calculate the Quadratic Equation");
Console.WriteLine("Input the value a:");
a=double.Parse(Console.ReadLine());
Console.WriteLine("Input the value b:");
b=double.Parse(Console.ReadLine());
Console.WriteLine("Input the value c:");
c=double.Parse(Console.ReadLine());
if(a==0)
{
Console.WriteLine("Not a quadratic Equation");
System. Environment. Exit(0);
}
d=b*b-4*a*c;
if(d==0)
{
Console.WriteLine("Roots are equal");
x1=-b/(2.0*a);
x2=x1;
Console.WriteLine("First Root="+x1);
Console.WriteLine("Second Root="+x2);
}
else if(d>0)
{

Dept of Computer Science, SSCASCW, Tumakuru Page 3


5th Sem BCA-DOTNET LAB BCACsP5.4

Console.WriteLine("Roots are real and different");


x1=(-b+Math.Sqrt(d))/(2.0*a);
x2=(-b-Math.Sqrt(d))/(2.0*a);
Console.WriteLine("First Root="+x1);
Console.WriteLine("Second Root="+x2);
}
else
{
Console.WriteLine("Roots are imaginary and Complex");
x1=(-b)/(2*a);
x2=Math.Sqrt(-d)/(2*a);
Console.WriteLine("The first root is {0} + i{1}",x1,x2);
Console.WriteLine("The second root is {0} - i{1}",x1,x2);
}

}
}

Dept of Computer Science, SSCASCW, Tumakuru Page 4


5th Sem BCA-DOTNET LAB BCACsP5.4

4. Write a Program in C# to demonstrate boxing and unBoxing.


using System;
class BoxingAndUnboxing
{
public static void Main(string[ ]args)
{
int m=10;
object a=m;//Referenece type
Console.WriteLine("The object type value is"+a);
object n=20;
int b=(int)n;//value type
Console.WriteLine("The object type value is"+b);
Console.WriteLine("Boxing and Unboxing is done");
Console.ReadLine( );
}

}
}

Dept of Computer Science, SSCASCW, Tumakuru Page 5

You might also like