Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <math.h>
  6.  
  7. #define MAX 512
  8. int getline(char s[], int lim) {
  9.     int c, i;
  10.     for (i = 0; i<lim && (c = getchar()) != EOF&&c != '\n'; ++i)s[i] = c;
  11.     s[i] = '\0';
  12.     while (c != EOF&&c != '\n')c = getchar();
  13.     return(i);
  14. }
  15.  
  16. int main(void) {
  17.     int i = 0, db = 0, lenyomva = 0;   
  18.     char s[MAX];
  19.     do {       
  20.         printf("Adjon meg egy szamot [0,1023]: ");
  21.         getline(s, MAX - 1);
  22.         i = atoi(s);
  23.  
  24.         if (i < 0 || i > 1023) { printf("A megadott szamnak 0 es 1023 kozott kell lennie!\n");}
  25.  
  26.         if (i>=512 && i <=1023) {
  27.             if (lenyomva == 0) { db++; }
  28.             if (db == 3) { printf("Lenyomva\n"); db = 0; lenyomva = 1; }
  29.         }
  30.         else if (i < 512 && i>=0){
  31.                 if (lenyomva != 1) { db--; }
  32.                 if (db == -3) {
  33.                     printf("Felengedve\n"); db = 0; lenyomva = 0;
  34.             }
  35.         }
  36.        
  37.     } while (i != -1);
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement