Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo -n "Enter a number: "
- read n
- p=2
- while [ $p -lt $n ]
- do
- if [ `expr $n % $p` -eq 0 ]
- then
- echo "The number $n is not a prime"
- exit
- fi
- p=`expr $p + 1`
- done
- echo "The number $n is a prime "
- =====
- See Output
- * New Project-201 70329日ロ+ « Execute ! > Share Code main.sh root 2 3 echo-n Enter a number: 4 read n 5 p-2 main.sh 7 while
- =====
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int n, i, isPrime = 0;
- printf("Enter a number:");
- scanf("%d",&n);
- for(i=2; i<=n/2; ++i)
- {
- if(n%i==0)
- {
- isPrime=1;
- break;
- }
- }
- if (isPrime==0)
- printf("The number %d is a prime.",n);
- else
- printf("The number %d is not a prime.",n);
- return 0;
- }
- ====
- See Output
- *New Project-201 70329 日ロ+《 웜 compile ! Execute ! > Share Code main.cx root 4 int mainO main.c intn, i, isPrime-0; 7 printf(
- Thanks, let me know if there is any concern.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement