answersLogoWhite

0


Best Answer

#!/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

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

#!/bin/sh

echo "Enter the number"

read number

temp=`expr $number - 1`

for i in `seq 2 $temp`

do

mod=`expr $number % $i`

if [ $mod = 0 ]

then

echo "Given Number is not a prime"

exit

fi

done

echo "Given number is a prime"

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Shell program for finding prime number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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

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.


How can you Write a suitable pseudo code to check whether a number is prime or not?

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


Write a c program to check whether a no is prime or not?

#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(); }


Prime number program in C using recursion?

//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; }


How do you write a C program to check whether a number is prime or not and to find the nth prime number?

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(); }

Related questions

Shell program to generate prime number between 1 and 50?

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.


What is finding the factors of a number that are all prime?

That's finding the prime factorization.


What is the difference between finding the factors of a number and finding the prime factors of a number?

No difference. Once you've found the factors of a number, the prime numbers on that list are the prime factors.


How is prime factorization different from finding factors of a number?

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.


Shell program to generate the prime numbers betwee 1 to 50?

2,3,5,7,9,11,13,17,19,23,29,31,37,39,41,43,47,49


What is the formula for finding a prime number?

Any number that has only two factors is a prime number.


What is the definition prime factorization?

Prime Factorization is finding which prime numbers multiply together to make the original number.


What are the prime factorization for composite numbers 1-100?

finding the prime factors of a composite number


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.


Why is finding prime factorization of a number useful?

It helps to reduce fractions.


How do you write a factor tree for a prime number?

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.


Program for print prime all number from 1 to 100 in foxpro?

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.