- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Bash program to check if the Number is a Prime or not
Bash also known as GNU bash is a command language and unix shell script is a command line interpreter for operating system. It was designed by Brian Fox and was a free software which replaced Bourne shell. It first released in 1989 and some became go to for login shell for linux based operating systems like macOS, Linux based softwares, etc.
Prime number is a number that has only two factors i.e. the number itself and 1. For example, 2 , 3 , 5, 7 , 11 , 13 , 17 , 19 , 23 , 29….
Here we are given a number, and we need to find whether the given number is prime or not.
Input : A number Output : “The number is prime ” OR “The number is not prime” based on the number.
Input : 23 Output : The number is prime
Step 1 − Loop from 2 to n/2, i as loop variable
Step 2 − if number is divisible, print “The number is not prime” and flag = 1;
Step 3 − if flag != 1, then print “The number is prime”.
Step 4 − Exit.
number=53 i=2 flag=0 while test $i -le `expr $number / 2` do if test `expr $number % $i` -eq 0 then flag=1 fi i=`expr $i + 1` done if test $flag -eq 1 then echo "The number is Not Prime" else echo "The number is Prime" Fi
The number is Prime
- Related Articles
- C# Program to check if a number is prime or not
- Python program to check if a number is Prime or not
- PHP program to check if a number is prime or not
- Write a C# program to check if a number is prime or not
- C++ Program to Check Whether a Number is Prime or Not
- C Program to Check Whether a Number is Prime or not?
- Java Program to Check Whether a Number is Prime or Not
- Bash program to check if the Number is a Palindrome?
- Check if a number is Quartan Prime or not in C++
- Check if a number is Primorial Prime or not in Python
- Check if a number is Primorial Prime or not in C++
- 8085 program to determine if the number is prime or not
- Python Program to Find if a Number is Prime or Not Prime Using Recursion
- Check if a number is a Pythagorean Prime or not in C++
- Write a Golang program to check whether a given number is prime number or not