לדלג לתוכן

4.1 - הקדמה - פתרון

פתרון לתרגיל 1

#include <stdio.h>

int main() {
    char name[100];
    int age;
    float height;

    printf("Enter name, age and height:\n");
    scanf("%s %d %f", name, &age, &height);

    printf("Hello %s! You are %d years old and your height is %.2f meters\n", name, age, height);
    return 0;
}

פתרון לתרגיל 2

#include <stdio.h>
#include <string.h>

int main() {
    char input[100];
    printf("Enter username:\n");
    scanf("%s", input);

    if (strncmp(input, "admin", 100) == 0) {
        puts("Welcome admin");
    } else {
        puts("Access denied");
    }

    return 0;
}