Write a program to accept a number from the user and display all the prime numbers from one up to the number entered by user. (Duration: 40 min)
using System;
class primeNumber
{
public void PrimeNum(int Num)
{
Boolean isPrime=true;
Console.WriteLine("\nThe prime numbers between 1-{0} is:",Num);
for (int i = 0; i <=Num; i++)
{
for (int j = 2; j<=Num; j++)
{
if (i !=j && i == 0)
{
isPrime = false;
break;
}
}
if (isPrime == true)
{Console.WriteLine("{0}",i);}
isPrime = true;
}
}
}
class EntryPoint
{
static void Main (string[]args)
{
int Num;
PrimeNumber FindPrimeNo = new PrimeNumber();
string str;
Console.WriteLine("Enter the number till which you want to show the prime Numbers");
str = Convert.ReadLint();
Num = Convert.PrimeNum(Num);
Console.ReadLint();
}
}
class primeNumber
{
public void PrimeNum(int Num)
{
Boolean isPrime=true;
Console.WriteLine("\nThe prime numbers between 1-{0} is:",Num);
for (int i = 0; i <=Num; i++)
{
for (int j = 2; j<=Num; j++)
{
if (i !=j && i == 0)
{
isPrime = false;
break;
}
}
if (isPrime == true)
{Console.WriteLine("{0}",i);}
isPrime = true;
}
}
}
class EntryPoint
{
static void Main (string[]args)
{
int Num;
PrimeNumber FindPrimeNo = new PrimeNumber();
string str;
Console.WriteLine("Enter the number till which you want to show the prime Numbers");
str = Convert.ReadLint();
Num = Convert.PrimeNum(Num);
Console.ReadLint();
}
}
Write a program to accept two numbers and check if the first is divisible by the second. In addition, an error message should be displayed if the second number is zero. (Duration: 40 min)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int num1, num2, result;
Console.WriteLine("Enter First Number");
num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter socond Number");
num2 = Convert.ToInt32(Console.ReadLine());
if (num2 == 0)
{
Console.WriteLine("You cannot divide by 0");
}
else
{
result = num1 % num2;
if (result ==0)
Console.WriteLine("Divisidle");
else
Console.WriteLine("Not DIvisible");
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int num1, num2, result;
Console.WriteLine("Enter First Number");
num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter socond Number");
num2 = Convert.ToInt32(Console.ReadLine());
if (num2 == 0)
{
Console.WriteLine("You cannot divide by 0");
}
else
{
result = num1 % num2;
if (result ==0)
Console.WriteLine("Divisidle");
else
Console.WriteLine("Not DIvisible");
}
}
}
}
Write a program to accept two numbers and display the quotient as a result. In addition, an error message should be displayed if the second number is zero or greater than the first number. (Duration: 20 min)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace two_number_1
{
class Program
{
static void Main(string[] args)
{
int num1, num2, result;
Console.WriteLine("Enter two numbers");
num1 = Convert.ToInt32(Console.ReadLine());
num2 = Convert.ToInt32(Console.ReadLine());
if (num2 != 0)
{
if (num2 < num1)
{
result = num2 / num2;
Console.WriteLine("result");
}
else
{
Console.WriteLine("A number cannot be divided by a number greater than itself");
}
}
else
{
Console.WriteLine("A number cannot be divided by zero");
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace two_number_1
{
class Program
{
static void Main(string[] args)
{
int num1, num2, result;
Console.WriteLine("Enter two numbers");
num1 = Convert.ToInt32(Console.ReadLine());
num2 = Convert.ToInt32(Console.ReadLine());
if (num2 != 0)
{
if (num2 < num1)
{
result = num2 / num2;
Console.WriteLine("result");
}
else
{
Console.WriteLine("A number cannot be divided by a number greater than itself");
}
}
else
{
Console.WriteLine("A number cannot be divided by zero");
}
}
}
}
No comments:
Post a Comment