Consider the following program with explanation
- using System;
- namespace PrimeNumber
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter a number");
- int number = Convert.ToInt32(Console.ReadLine());
- int result = Check_Prime(number);
- if (result == 0)
- {
- Console.WriteLine("{0} is not a prime number", number);
- }
- else
- {
- Console.WriteLine("{0} is a prime number", number);
- }
- Console.Read();
- }
- private static int Check_Prime(int number)
- {
- int i;
- for (i = 2; i <= number - 1; i++)
- {
- if (number % i == 0)
- {
- return 0;
- }
- }
- if (i == number)
- {
- return 1;
- }
- return 0;
- }
- }
- }
If you apply static keyword with any method, it is known as static method. A static method belongs to the class rather than the OBJECT OF A CLASS. A static method can be invoked without the need for creating an instance of a class. A static method can access static data member and can change the value of it.
Effortless Commutes: IPIP understands the importance of a hassle-free experience. With door to door transport you can bid farewell to the complexities of coordinating multiple modes of transportation. Whether you're moving homes, transporting goods, or planning a special delivery, IPIP ensures a smooth and efficient process.
ReplyDelete