In this tutorial, we will discuss the concept of the C# program to print all prime numbers between 1 to 100 using for loop
In this post, we will learn how to print all prime numbers between 1 to 100 using for loop in C# programming language with Example program.
Prime number
The number that can be divided by 1 and itself. it is called a prime number
for Example 2,3,5,7,11,13…
In this program, the user declares and initializes variables then it will print prime numbers from 1 to 100, using the for loop in the C# language.
Program 1
//print prime numbers between 1 to 100 using for loop using System; namespace primeNumber { class first1toNPrime { static void Main(string[]args) { Console.WriteLine("print prime number between 1 to 100"); bool isPrime=true; for(var i=2; i<=100; i++){ for(var j=2; j<=100; j++) { if(i!=j && i%j==0){ isPrime=false; break; } } if(isPrime){ Console.Write(i+","); } isPrime=true; } Console.ReadKey(); } } }
When the above code is executed, it produces the following result
print prime number between 1 to 100 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,
In this program, the user declares and initializes variables then it will print prime numbers from 1 to 100, using the for loop in the C# language.
Program 2
//C# program to print all prime numbers between 1 to 100 using for loop using System; namespace primeNumber { class first_N_Prime { static void Main(string[]args) { int i=1,count=0; Console.WriteLine("Prime numbers between 1 to 100 "); for(int n=0; n<100; n++){ count=0; for(int j=1; j<=i; j++){ if(i%j==0) count++; } if(count==2){ Console.Write(i+","); } i++; } } } }
When the above code is executed, it produces the following result
Prime numbers between 1 to 100 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,
Program to find whether a Number is Prime or Not in C++
Program to find whether a Number is Prime or Not in C
Program to find whether a Number is Prime or Not in Java
Program to find whether a Number is Prime or Not in Python
Program to find whether a Number is Prime or Not in PHP
Program to find whether a Number is Prime or Not using the PHP function
C++ program to find first n prime numbers
Java program to find first n prime numbers
C program to find first n prime numbers
C# code to print first n prime numbers using for loop
C# code to print first n prime numbers using while loop
C# code to print first n prime numbers using do-while loop
C# code to print 1 o n prime numbers using for loop
C# code to print 1 to n prime numbers using while loop
C# code to print 1 to n prime numbers using do-while loop
C code to 5 ways to check whether the given integer is Even or Odd
Java code to 5 ways to check whether the given integer is Even or Odd
C++ code to 5 ways to check whether the given integer is Even or Odd
Python code to 5 ways to check whether the given integer is Even or Odd
10 best Ways to Subtract Two Numbers in Java (With Examples) In this article, we…
Array Data Structure: Definition, Types, Operations & Advantages Array Data Structure Introduction In this post,…
20 ways to subtract two numbers in Java In this article, we will discuss the…
10 simple ways to add two numbers in Java In this article, we will discuss…
Write a Python program to find the first n prime numbers In this article we…
Python: Calculate Average of odd and even in a list using loops In this post,…