Skip to content

Commit

Permalink
Merge pull request #330 from skamp91/myPrime
Browse files Browse the repository at this point in the history
Implementation of Prime-Check in C #319
  • Loading branch information
Kanhakhatri065 authored Oct 6, 2020
2 parents 924b720 + c1fc409 commit 8559749
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions problems/prime/prime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main (void) {
float wurzelHeron = 0;
float x = 0;

int zahl = 0;
int teiler = 0;
int i;

bool prim;

printf("\nBitte geben Sie eine Zahl ein: ");
scanf("%d",&zahl);
if (zahl < 2) {
printf("Das ist KEINE primzahl");
return (EXIT_SUCCESS);
}

x = (zahl + 1)/2;

for (i = 0; i < 3; i++); {
wurzelHeron = 0.5*(x+zahl/x);
x = wurzelHeron;
}

int wurzel = wurzelHeron;

prim = true;
for (teiler = 2; teiler <= wurzel2; teiler++) {
if (zahl%teiler == 0) {
prim = false;
}
}

if (prim == true) {
printf("\n++++++++ BINGO ++++++++ \n\n %d ",zahl);
}
}else{
printf("\n++++++++ ZONK ++++++++ \n\n %d ",zahl);
}


return (EXIT_SUCCESS);
}

0 comments on commit 8559749

Please sign in to comment.