answersLogoWhite

0

A number is a Prime number if it is divisible by only 1 and itself. So make use of for loop and check for this condition.

int i,num,flag = 0;//num is the number to check

scanf("%d", &num);

for( i=2; i

if( num%i == 0)//it has other divisors

flag = 1;

}

if( !flag)

printf("The number is prime\n");

else

printf("The number is not prime\n");


User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

C program to find prime number?

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#includemain(){long int a,b,c;printf("Enter the number: ");scanf("%ld",&a);for (b=2;b


What is the C programming of check the prime number with flow chart?

flow t prime numberchar


Write a c program to find out the prime numbers between 1 to 500?

Here is a simple program to generate prime numbers upto a given specific number /*Prime No. from 1 to 50*/ /*By-Himanshu Rathee*/ #include<stdio.h> #include<conio.h> void main() { int i,j,n; clrscr(); printf(" Enter the number upto which we have to find the 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; /*Number is divisble by some other number. So break out*/ if(i==j) printf("\t%d",i); /*Number was divisible by itself (that is, i was same as j)*/ } /*Continue loop upto nth number*/ getch(); }


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


C plus plus code that determine prime number?

#include <iostream.h> main() { int a; cout<<"enter a number : "; cin>>a; cout<<endl; if (a%2-1) cout<<"it is a prime number"; else cout<<"it is not a prime number" return 0; } ------------------------------------------ output: enter a number : 30 it is a not a prime number

Related Questions

What is the code of a c program that will read in a positive integer value and determine If the integer is a prime number and If the integer is a Fibonacci number?

see the program


How do you write a c program to get a range from user and give a list of prime numbers?

To get all tutorials of "c programming" Reference:cprogramming-bd.com/c_page2.aspx# prime number


How do you find prime no in gwbasic program?

10 input "enter a no."; n 20 for i = 1 to n 30 if n mod i = 0 then c = c +1 40 next i 50 if c = 2 then print "prime number" else print "not a prime number" 60 end


Write a c program to find given number is prime or not?

Yes, do write, or if you're too lazy to your homework, use google.


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


What is the Program for composite and prime numbers in c?

#include<iostream.h> #include<conio.h> int main() { int i,n; clrscr(); cout<<"PROGRAM TO CHECK IF THE NUMBER IS PRIME OR NOT:"<<endl; cout<<"Enter a number:"; cin>>n; for(int i=2;i<n;i++) { if(n%i==0) cout<<"\nTHE NUMBER IS COMPOSITE"<<endl; else cout<<"\nTHE NUMBER IS PRIME"<<endl; } return 0; }


A program to find that the input number is prime or not?

Use Wolfram|Alpha... go to the related link below, Wolfram|Alpha, and type in (is __ (number) prime) and then the program will compute that and tell you if it is prime or composite.


How can you check whether a number is prime or not by a C program using functions?

#include<iostream.h> #include<conio.h> void prime(int n) { clrscr(); int num; cout<<"enter the numbers"<<endl; cin>>num; prime(num); getch(); } void prime(int n) { int prime=1,i; for(i=2;i<=n/2;i++) if(n%i==1) prime=0; if(prime==1) cout<<"the number"<<n>>"is prime"; else cout<<"the number"<<n<<"is not prime"; }


How do you write a java program to check a number is twisted prime or not?

public class TwistedPrime { public static void main(int n)//Enter a number { int num,s=0,c=0,d; num=n; while(n>0) { d=n%10; s=s*10+d; n=n/10; { for(int i=1;i<s;i++) { if(s%i==0) c++; } } } if(c==1) System.out.print("Number is Twisted Prime"); else System.out.print("Number is not T.P."); } }


How do you write a program in objective c numbers 1-100 prime numbers?

fdsgfhgdfhgdf


When you multiply a prime and a composite number do you always get a composite number?

Product of a prime number and a composite number results in a composite number.Now consider the product of a composite number(a) and a prime number(b) is equal to c.i.e. c = a x bIt is clear that c is divisible by both a and b.Also c is divisible by itself and 1, this means that c has more than two factors.A number having more than two factors is composite, therefore product of a prime number and a composite number results in a composite number.


Which number is a prime number a.14 b.15 c.23 d.25?

c.23