#!/bin/sh
i=2
rem=1
echo -e "Enter a number: \c"
read num
if [ $num -lt 2 ]; then
echo -e "$num is not prime\n"
exit 0
fi
while [ $i -le `expr $num / 2` -a $rem -ne 0 ]; do
rem=`expr $num % $i`
i=`expr $i + 1`
done
if [ $rem -ne 0 ]; then
echo -e "$num is prime\n"
else
echo -e "$num is not prime\n"
fi
Oh, dude, you wanna find prime numbers? Alright, here's a simple C program for ya: You loop through numbers from 1 to 500, check if each number is prime by dividing it only by numbers up to its square root (efficient, right?), and if it's only divisible by 1 and itself, boom, you got a prime number. Print those bad boys out and voilà, you're done. Like, easy peasy, lemon squeezy!
Begin Read num for(i=2; i<num; i++) if(num%2==0) then print "the number is not a prime no."; else if print "the number is prime"; end if Stop
#include<stdio.h> #include<conio.h> int i=1, count=0,n; clrscr(); printf("Enter Any Number"); scanf("%d", &n); while(i<n) if(n%i==0) { count++; i++; } if(count==2) printf("Given Number is Prime"); else printf("Given Number is not Prime"); getch(); }
//Program to check number is prime or not using recursive function #include<stdio.h> #include<stdlib.h> void prime(int num,int count) { if(count<num) { if(num%count==0) { printf("%d is not Prime Number\n",num); goto exit; } count += 1; if(count<num) { prime(num,count); } } if(num==count) { printf("%d is a Prime Number\n",num); } exit: return 0; } int main() { system("cls"); int gvar; printf("Enter the number = "); scanf("%d",&gvar); prime(gvar,2); printf("\nashokakhil@gmail.com\n"); system("PAUSE"); return 0; } I think this can be another solution #include<stdio.h> #include<conio.h> int prime(int); main() { int i=1,r; clrscr(); r=prime(i); if(r==1) printf("\n\n\tNo is prime "); getch(); } int prime(int i) { int n=1,ans,flag=1; i++; ans=n%i; if(ans==0) { printf("\t\t\n\nNo is not prime"); flag=0; return flag; } if((i!=n-1)&&(n!=1)) flag=prime(i); return flag; }
int number; int i=2; while (i<number) { if(number%i==0) { printf("Not a prime no."); break; } else printf("number entered is prime"); getch(); }
There are several shell programs available for download on the Internet that will generate prime numbers. The best way to find a prime number is through calculation, however.
That's finding the prime factorization.
No difference. Once you've found the factors of a number, the prime numbers on that list are the prime factors.
All numbers have factors. Some factors are prime numbers, some are composite numbers, one is neither. When finding the factors of a number, you find all the factors. The prime factorization is a multiplication string of just prime factors that will total the given number.
2,3,5,7,9,11,13,17,19,23,29,31,37,39,41,43,47,49
Any number that has only two factors is a prime number.
Prime Factorization is finding which prime numbers multiply together to make the original number.
finding the prime factors of a composite number
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.
It helps to reduce fractions.
The purpose of a factor tree is to notate the process of finding the prime factorization. If a number is already prime, a factor tree is not necessary.
Prime numbers are numbers that are only divisible by themselves and the number 1. You can write a program to print all prime numbers from 1 to 100 in FoxPro.