Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool test = true;
- while (test)
- {
- int i = 0;
- n[i] = getchar();
- while (n[i] != 'n')
- {
- i++;
- n[i] = getchar();
- if (n[i] >= '0' && n[i] <= '9')test = false;
- else
- {
- test = true;
- cout << "Введены некорректные данные, повторите попытку: " << endl;
- break;
- }
- }
- }
- test = false;
- n[i] != 'n'
- n[i] != 'n'
- n[i] = 0;
- char n[1000];
- for(bool ok = false;!ok;puts("Retry"))
- {
- ok = true;
- printf("Enter number: ");
- fgets(n,1000,stdin);
- if (n[strlen(n)-1] == 'n') n[strlen(n)-1] = 0;
- for(int i = 0; n[i]; ++i)
- if (!isdigit(n[i]))
- {
- ok = false;
- break;
- }
- }
- string s = "a";
- for(;s.find_first_not_of("0123456789") != string::npos;)
- {
- cout << "Enter number: ";
- getline(cin,s);
- }
- bool test = true;
- while (test)
- {
- cout << "Введите число, факториал которого вам нужно найти. Число доолжно быть от 10 дo 100: ";
- getline(cin, N);
- for (int i = 0; i < N.size(); i++)
- {
- if (N[i] >= '0' && N[i] <= '9')test = false;
- else
- {
- test = true;
- cout << "Некорректный ввод, вы дурак!" << endl;
- cout << endl;
- break;
- }
- }
- if (N.size() != 2)
- {
- test = true;
- cout << "Введенное число должно быть из диапозона [10; 100]" << endl;
- }
- }
- #include <stdio.h>
- #include <stdlib.h>
- static inline int skipnl (int n, int *err) {
- *err = 1;
- int c;
- while ((c = getchar()) != EOF && c != 'n');
- return n;
- }
- int
- get_digits (char *input, int lim, int *err)
- {
- int c, n = 0;
- *err = 0;
- if (lim < 1) {
- printf("call error: lim = %dn", lim);
- return skipnl(0, err);
- }
- while ((c = getchar()) != EOF) {
- if (c == 'n') {
- if (!n)
- continue;
- return n;
- }
- if (c >= '0' && c <= '9') {
- if (n < lim)
- input[n++] = c;
- else {
- printf("too long, max: %dn", lim - 1);
- return skipnl(n, err);
- }
- } else {
- printf("incorrect input: '%c'n", c);
- return skipnl(n, err);
- }
- }
- return n;
- }
- int
- main (int ac, char *av[])
- {
- char s[1000];
- int n, err;
- while (!feof(stdin)) {
- fputs("Enter: ", stdout); fflush(stdout);
- err = 0;
- n = get_digits(s, 999, &err);
- s[n] = 0;
- if (n && !err)
- puts(s);
- }
- return puts("End") == EOF;
- }
- #include <stdio.h>
- #include <stdlib.h>
- static inline int check_cvt_chr (char *p)
- {
- if (*p < '0' || *p > '9') {
- printf("invalid input: '%c'n", *p);
- return 0;
- }
- *p -= '0';
- return 1;
- }
- int
- check_convert (char *s, ssize_t l)
- {
- size_t i = 0, j = l - 1;
- for (; i < j; i++, j--)
- if (check_cvt_chr(s + i) && check_cvt_chr(s + j)) {
- char t = s[i];
- s[i] = s[j];
- s[j] = t;
- } else
- return 0;
- return i == j ? check_cvt_chr(s + i) : 1;
- }
- static void
- print (char *s, ssize_t l)
- {
- while (l)
- putchar(s[--l] + '0');
- puts("");
- }
- int
- main (int ac, char *av[])
- {
- size_t sz;
- ssize_t len;
- char *str = 0;
- while (fputs("Enter: ", stdout), fflush(stdout),
- (len = getline(&str, &sz, stdin)) > 0) {
- str[--len] = 0; // erase 'n' at the end
- if (check_convert(str, len))
- print(str, len);
- free(str);
- str = 0;
- }
- return puts("End") == EOF;
- }
Add Comment
Please, Sign In to add comment