class Program
{
static void Main(string[] args)
{
int sum = 0, count = 0;
Console.WriteLine("Enter the size of the array");
int n = int.Parse(Console.ReadLine());
int[] arr = new int[n];
Console.WriteLine("Enter the Array Elements");
for (int i = 0; i < n; i++)
{
arr[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("Your array element");
for (int i = 0; i < n; i++)
{
Console.Write(arr[i] + " ");
}
Console.WriteLine();
Console.WriteLine("Your prime numbers are:");
for (int i = 0; i < n; i++)
{
int num = 0;
for (int j = 2; j < arr[i]; j++)
{
if (arr[i] % j == 0)
{
num = 1;
break;
}
}
if (num == 0)
{
Console.WriteLine(arr[i]);
sum = sum + arr[i];
count++;
}
}
Console.WriteLine("The number of prime numbers is:{0}", count);
Console.WriteLine("The sum of prime no. is:{0}", sum);
Console.WriteLine();
Console.ReadLine();
}
}
OUTPUT:
No comments:
Post a Comment