1 solutions
-
0
C :
#include<stdio.h> void fun(int n) { int i; for(i=2;i<n-1;i++) if(n%i==0) { printf("Not Prime!\n",n); break; } if(i==n-1) printf("Prime!\n",n); } void main() { int n,i; scanf("%d",&n); fun(n); }C++ :
#include<stdio.h> int main() {int sushu(int); int l; scanf("%d",&l); if(l>=1) {if(sushu(l)) printf("Prime!\n"); else printf("Not Prime!\n"); } else printf("Error!\n"); return 0; } int sushu(int l) { int world=1,z; for(z=2;z<l/2&&world==1;z++) if(l%z==0) world=0; return(world); }Pascal :
program acm26338; var n:longint; function ss(n:longint):string; var i,c:longint; begin c:=0; for i:=1 to trunc(sqr(n)) do if n mod i=0 then c:=c+1; if c=2 then ss:='Prime!' else ss:='Not Prime!'; end; begin read(n); writeln(ss(n)); end.
- 1
Information
- ID
- 18062
- Time
- 1000ms
- Memory
- 12MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By