Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <math.h>
- #define MAX 512
- int getline(char s[], int lim) {
- int c, i;
- for (i = 0; i<lim && (c = getchar()) != EOF&&c != '\n'; ++i)s[i] = c;
- s[i] = '\0';
- while (c != EOF&&c != '\n')c = getchar();
- return(i);
- }
- int main(void) {
- int i = 0, db = 0, lenyomva = 0;
- char s[MAX];
- do {
- printf("Adjon meg egy szamot [0,1023]: ");
- getline(s, MAX - 1);
- i = atoi(s);
- if (i < 0 || i > 1023) { printf("A megadott szamnak 0 es 1023 kozott kell lennie!\n");}
- if (i>=512 && i <=1023) {
- if (lenyomva == 0) { db++; }
- if (db == 3) { printf("Lenyomva\n"); db = 0; lenyomva = 1; }
- }
- else if (i < 512 && i>=0){
- if (lenyomva != 1) { db--; }
- if (db == -3) {
- printf("Felengedve\n"); db = 0; lenyomva = 0;
- }
- }
- } while (i != -1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement