1.WRITE A CONSOLE PROGRAM PRIME OR NOT>
PROGRAM:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class
Program
{
static void Main(string[] args)
{
int a, i, b = 0;
Console.WriteLine("Enter the number to check prime or not");
a = int.Parse(Console.ReadLine());
for (i = 2; i <= a / 2; i++)
{
if (a % i == 0)
{
Console.WriteLine("The number " + a + " is not
prime");
b++;
break;
}
}
if (b == 0)
Console.WriteLine("The number " + a + " is prime
number");
}
}
}
OUTPUT:
2.WRITE A CONSOLE
PROGROM TO TRIM A STRING>
PROGRAM:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class
Program
{
static void Main(string[] args)
{
string myString = "
prasun ";
System.Console.WriteLine("The String Before Trimming : (" +
myString + ")");
System.Console.WriteLine("The String
After Trimming : (" + myString.Trim() + ")");
Console.Read();
}
}
}
OUTPUT:
PROGRAM:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EvenOdd
{
class
Program
{
static void Main(string[] args)
{
int num,sq;
Console.WriteLine("Enter a Number to Check a Number is Perfect
Square or Not");
num = int.Parse(Console.ReadLine());
try
{
sq =int.Parse(Math.Sqrt(Convert.ToDouble(num.ToString())).ToString());
if (sq*sq==num)
Console.WriteLine("The number " + num + " is Perfect
Square Number");
}
catch
{
Console.WriteLine("The number " + num + " is not Perfect
Square Number");
}
}
}
OUTPUT:
4.WRITE A CONSOLE PROGRAM EVEN OR ODD>
PROGRAM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int n;
Console.WriteLine("Enter the
number");
n = int.Parse(Console.ReadLine());
if (n % 2 == 0)
Console.WriteLine("The
number " + n + " is an even number");
else
Console.WriteLine("The
number " + n + " is an odd number");
}
}
}
OUTPUT :
5.WRITE A CONSOLE
PROGRAM TO GENERATE THE SUM OF N NUMBER>
PROGRAM:
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace b_to_d
{
class Program
{
static void Main(string[] args)
{
int i, sum = 0, n;
Console.Write("Enter the Nth
Number : ");
n = int.Parse(Console.ReadLine());
for (i = 0; i <= n; i++)
{
sum = sum + i;
}
Console.WriteLine("\nSum of N
Numbers : " + sum);
Console.ReadLine();
}
}
}
OUTPUT :
0 Comments
Post a Comment