Created
October 5, 2017 20:21
-
-
Save unaipme/641b76ca8f00d39f7efbf6eafbb85a3c to your computer and use it in GitHub Desktop.
Zenbaki oso bat eskatu eta zenbaki lehena (número primo) den edo ez pantailan idazten duen algoritmoa idatzi.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _CRT_SECURE_NO_WARNINGS | |
#include <stdio.h> | |
int main(void) { | |
int n, lehena, i; | |
char str[128]; | |
printf("Sartu zenbakia: "); | |
fgets(str, 128, stdin); | |
sscanf(str, "%d", &n); | |
lehena = 1; | |
i = 2; | |
while (i < n / 2 && lehena) { | |
if (n % i == 0) lehena = 0; | |
i++; | |
} | |
if (lehena) { | |
printf("Zenbakia lehena da\n"); | |
} else { | |
printf("Zenbakia ez da lehena\n"); | |
} | |
printf("Sakatu intro jarraitzeko..."); | |
getchar(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment