- Any number which is divisible by 1 and itself is known as prime number.
- To check prime number or not in c programming we need to use for loop and iterate from 2 to half of the number.
- If any number is divisible then it is non prime number, we can exit the loop.
- Now we need to check prime numbers from 1 to 100 or 1 to n.
- Logic is same and we are adding one more for loop for 1 to N numbers.
- Now we will iterate for loop from 1 to n and check prime or nor for each number.
- Lets see an example program on c to check prime numbers from 1 to N.
- Prime number program in c using for loop.
- prime number program in c using while loop
- prime number using while loop in c
Master C programming with Example programs, C programming practices for absolute beginners to excel in the industry
- prime number using for loop in c
- C program to check prime number using while loop
- #include <stdio.h>
- int main()
- {
- int n, i,j, count = 0;
- printf("Enter a Number");
- scanf("%d",&n);
- for(i=2;i<=n;i++)
- {
- for(j=2;j<i;j++)
- {
- if(i%j==0)
- break;
- else if(i==j+1)
- printf("%d\n",i);
- }
- }
- getch();
- }
Output:
You might like:
- C program to check whether the triangle is right angled triangle
- Write a c program to generate fibonacci series without recursion
- Write a c program to generate fibonacci series using recursion
- Sum of Two integers in c
- Matrix multiplication in c program with explanation
- Factorial program in c without recursion
- C program to check number is armstrong number or not
- Check Armstrong number in c using recursive function
- C program for even or odd using for loop
- C program to check odd or even without using modulus operator and division operator
- Prime number program in c using for loop and while loop
- C program to print prime numbers from 1 to n
- C program to print multiplication table using while loop and for loop
- C program to convert binary to decimal using for loop
- C program to reverse a number using while loop and for loop
- C program to find sum of n numbers using for loop
- C program to find leap year using if else
- c program to check leap year using conditional operator
- C program to print patterns of numbers,alphabets and stars in a pyramid shape
- C program to swap two numbers without using third variable and using functions
- C Program to swap two numbers without using third variable
- Write a C program to swap two integer arrays
- C program for swapping of two strings
- C program to print given number in words
- C program to print 1 to 100 without using loop
- C program to find ASCII value of a string
- Convert string to integer c programming
- C program to display characters from a to z using loop
- C programming power function example program
- C program for addition subtraction multiplication and division using switch case
- C program to delete an element in an array
- C program to insert an element in an array
- Switch case in c example program
- Prime number program in c using for loop
- Fibonacci series in c without recursion
No comments