#include<stdio.h>
#include<conio.h>
main()
{
int i,j,n;
printf(" Enter the number upto which you want to find prime number ");
scanf("%d",&n);
printf("\n");
for(i=2;i<=n;i++)
{
for(j=2;j<=i-1;j++)
if(i%j==0)
break;
if(i==j) printf("\n\t%d",i);
}
getch();
}
//for example if u want to find Prime number between 1 to 100 enter 100..
// u will get prime number between 1 to 100
//tested in bloodshed dev c++
Chat with our AI personalities
I am providing a succinct and easy to understand version of the program. I have run it in 3-4 compilers and it works perfect. Mind you, you should not enter a number more than 2147483647 (which is the largest number a variable can process in C!). If you do, no problem, but it will display all numbers above it, including the even numbers to be prime. So here you are:
#include
#include
main()
{
long int a,b,c;
printf("Enter the number: ");
scanf("%ld",&a);
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("\nenter a number...\n");
scanf("%d",&n);
if (n!=2 && n%2==0)
printf("%d isn't prime..", n);
else
printf("%d is either prime or not..", n);
getch();
}
To write a C program to find prime numbers between 1 to 500, you can use a nested loop structure. In the outer loop, iterate from 2 to 500, and in the inner loop, check if the number is divisible by any number from 2 to the square root of the number. If it is not divisible by any number other than 1 and itself, then it is a prime number. Print out all prime numbers found within the specified range. Remember to include necessary header files, such as <stdio.h>, and use appropriate logic to implement the program efficiently.
Write a program to find the number and sum of all integers from 100 to 300 that are divisible by 11
It should not be even (except for 2), and must not be dividable with any odd number between 3 and its square-root.
flow t prime numberchar
write a c++ program to convert binary number to decimal number by using while statement