C sharp program to print prime numbers




















The following example takes one input from the console and then checks whether that number is a prime number or not. In the following example, we will take two numbers from the console and then print the prime numbers present between those two numbers. Here, in this article, I try to explain what is a prime number and how to check whether a number is prime or not using a console application.

In the end, we also discussed how to print the prime numbers between a range. This can be achieved in C programs by defining logics using various loops and conditional statements, such as the for loop, if condition, if else condition, while loop, etc.

Generic; using System. Linq; using System. Text; using System. Program Explanation: The above program is a classic example of the use of loops and conditional operators for determining the prime numbers in a fixed range of numbers. The program above uses a lower limit of Natural number i.

The loop then passes through the range and uses the natural operation of modulo on the variable a by the divisor b. The modulo operator returns 0 if a is perfectly divisible by b indicating the fact that b as a smaller natural number is a factor for the composite number a. Now we employed the conditional operator to print the number in the output console in case we received the number as a prime number.

Parse Console. Learn more. Print the prime numbers from 0 to 10, Ask Question. Asked 6 years, 10 months ago. Active 3 years, 1 month ago. Viewed 28k times. Improve this question. Santiago Mendoza Flores Santiago Mendoza Flores 23 1 1 gold badge 1 1 silver badge 4 4 bronze badges.

If you're not familiar with using Breakpoints to walk line-by-line through a Debug build then this is a good opportunity to try it out — STW. I can't use a boolean type of data. You are already using 3 booleans in the form of conditions in your snippet.

Add a comment. Active Oldest Votes. Try this with no bool variable!!! Improve this answer. Ankush Madankar Ankush Madankar 3, 4 4 gold badges 36 36 silver badges 70 70 bronze badges. The problem here is that i can't use bool; only what I said. Reinforcement Learning. R Programming. React Native.

Python Design Patterns. Python Pillow. Python Turtle. Verbal Ability. Interview Questions. Company Questions. Artificial Intelligence. Cloud Computing.



0コメント

  • 1000 / 1000