Pages

Tampilkan postingan dengan label prime. Tampilkan semua postingan
Tampilkan postingan dengan label prime. Tampilkan semua postingan

Selasa, 17 Mei 2016

C Program to check number is prime or composite

C# Program to check entered number is prime or composite 

Program Statement:
Write a program that takes an integer as an input from user and prints if it is a prime or composite number.

Solution:
 static void Main(string[] args)
{
int num, i;
Console.WriteLine("Enter the number to check number is prime or composite");
num=Convert.ToInt32(Console.ReadLine());
i = 2;
while (i <= num - 1)
{
if (num % i == 0)
{
Console.WriteLine("composite number: "+num);
break;
}
i++;
}
if (i == num)
Console.WriteLine("prime number: " + num);
Console.ReadLine();

}


Read More..

Selasa, 03 Mei 2016

C program to print Factorial of all Prime numbers in csharp

C# program to print Factorial of all Prime numbers

Program Statement:
Write a program using loop which takes one value n from user and show the factorial of all prime numbers which are less then n. e.g. if n = 10 then program will print the factorial of 2,3,5,7.

Solution:
 public class fop
{
int x, a, b, p, fac=1;
public void fact()
{
Console.WriteLine(" Show factorial of primes less than n ");
Console.Write(" Enter ending point : ");
x = Convert.ToInt32(Console.ReadLine());
for (a = 2; a < x; a++)
{
p = 1;
for (b = 2; b < a; b++)
{
if (a % b == 0)
{ p = 0; }
}
if (p == 1)
{
fac = 1;
for (int c = 1; c <= a; c++)
{ fac = fac * c;}
Console.Write(" Factorial of {0} is : {1} ", a,fac);
}
}
Console.WriteLine(" ");
}
}


Read More..

Selasa, 26 April 2016

www pmo gov pk Prime Minister Office website PM youth policy


PM youth policy
PM youth policy 
www.pmo.gov.pk - Prime Minister Office website down after Nawaz Sharif Speech
Prime Minister Office website www.pmo.gov.pk got down after PM Nawaz Sharif announced its website during his address to youth of Pakistan.
Same happend to BISP tracking system last year when Benazir Income support scheme started and web got down for a long time
The website got down due to heavy traffic. The website will be up in few hours.

PM has announced that all the material regarding PM youth policy including application forms and information about youth loan scheme and youth laptop scheme  is available on the website.
Read More..

Kamis, 17 Maret 2016

C Program to Print number of prime values in the array

C# Program to Print number of prime values in the array

Program Statement:
Write a program which takes 10 values from user in an array and then show the number of prime values in the array.

Solution:
 public class arr
{
int c, count = 0, n;
int[] array = new int[10];
public void arr_func()
{
Console.WriteLine(" Enter 10 element only! ");
for (int x = 0; x < 10; x++)
array[x] = Convert.ToInt32(Console.ReadLine());
for (int y = 0; y < 10; y++)
{
n = array[y];
for (c = 2; c <= n - 1; c++)
{
if (n % c == 0)
{ break; }
}

if (c == n)
{
count++;
Console.WriteLine(" {0} is prime number! ", n);
}
}
Console.WriteLine(" Number of prime values : {0} ", count);
}
}


Read More..

Jumat, 11 Maret 2016

C Program which calculated factorial to prime function

C# Program which calculated factorial to prime function

Program Statement:
Write two functions max(int,int) and prime(int). max function will take two arguments and will return the maximum of two numbers in main. Then main function will pass this calculated factorial to prime function which will show that passed value is prime or not.

Solution:
 public class _max
{
public int max(int a, int b)
{
if (a > b)
return a;
else
return b;
}
public void prime(int n)
{
if (n == 1)
Console.WriteLine(" {0} is maximum but not prime number! ", n);
if (n >= 2)
{
if (n % 2 != 0)
{
Console.WriteLine(" {0} is maximum and Prime number! ", n);
}
else
{ Console.WriteLine(" {0} is maximum but not a Prime number! ", n); }
}
}
}


Read More..