Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <locale.h>
- #include <ctype.h>
- #include <math.h>
- #include <string.h>
- int prime (int a);
- int main()
- {
- //FILE *in;
- setlocale (LC_ALL, "Rus");
- long int n = 1;
- int i = 0, k = 1;
- //in = fopen("in.txt", "rt");
- char c;
- int pos;
- char* num = malloc(10);
- printf ("Желательно ввести небольшое натуральное число: \n");
- input:
- memset(num, ' ', 10);
- pos = 0;
- while (scanf("%c", &c)) {
- if (!pos && (isspace(c) || c == '\t' || c == '0')) {
- continue;
- } else if (pos > 9) {
- getline(&num, 0, stdin);
- printf("о-оо-он с-слишком большой, он не влезет, семпай\n");
- goto input;
- } else if (c == '\n') {
- break;
- } else if (isdigit(c)) {
- num[pos] = c;
- ++pos;
- } else {
- getline(&num, 0, stdin);
- printf("нехорошие у тебя символы, попробуй ещё раз\n");
- goto input;
- }
- }
- n = atoi (num);
- printf ("\n%ld\n", n);
- i = 2;
- while (k < n) {
- if (prime (i)) {
- printf ("%10d", i);
- k ++ ;
- }
- i++;
- }
- return 0;
- }
- int prime (int a) {
- int i;
- for (i = 2; i < (int)(ceil(sqrt(a))); i++) {
- if (a % i == 0) return 0;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement