answersLogoWhite

0

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

Still curious? Ask our experts.

Chat with our AI personalities

BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
More answers

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

User Avatar

Wiki User

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