חזור לתיקייה: גליון 1

hw1q2

חיפוש בתיקיה
Ctrl K
לחץ כאן או הקש Ctrl K כדי לחפש בכל התיקיה

    hw1q2

    02340114

    מבוא למדמח מ

    רשימות הרצאה לקריאה בשבת

    hw1q2

    הופק מתוך תקיית התואר של שקד

    uni-folder.vercel.app

    hw1q2.c

    הערה (קובץ קוד)

    קובץ זה הוא קובץ קוד מסוג C.

    #include <stdbool.h>
    #include <stdio.h>
    
    int main(void)
    {
        int userInput;
    
        if (scanf("%d", &userInput) > 0)
        {
            if (userInput < 0)
            {
                printf("-");
                userInput = -userInput;
            }
    
            bool beforeDigit = true;
            while (userInput > 0)
            {
                int currentDigit = (userInput % 10);
                if (beforeDigit && currentDigit != 0)
                {
                    beforeDigit = false;
                }
    
                if (!beforeDigit || currentDigit != 0)
                {
                    printf("%d", currentDigit);
                }
                userInput /= 10;
            }
            printf("\n");
        }
        else
        {
            printf("Error in input!\n");
        }
    
        return 0;
    }