#30 (C) while4.c

2022. 9. 21. 23:32C

#include <stdio.h>
int main()
{
    /*
        int total=0;
        int num=0;
   
        do
        {
            printf("Enter the number (0 to quit): ");
            scanf("%d", &num);
            total += num;
        } while (num!=0);
        printf("Total:%d\n", total);
        return 0;

   

        int total=0;
        int num;
        while (num!=0)
        {
            printf("Enter the number (0 to quit): ");
            scanf("%d", &num);
            total += num;
        }
        printf("Total: %d\n", total);
        return 0;
    */
        int num=0;
        int total=0;
        printf("Enter the number (0 to quit): ");
        scanf("%d", &num);
        total += num;
        while (num!=0)
        {
            printf("Enter more numbers (0 to quit): ");
            scanf("%d",&num);
            total += num;
        }
        printf("Total: %d\n", total);
        return 0;

}

'C' 카테고리의 다른 글

#32 (C) while6.c  (0) 2022.09.21
#31 (C) while5.c  (0) 2022.09.21
#29 (C) while3.c  (0) 2022.09.21
#28 (C) while2.c  (0) 2022.09.21
#27 (C) two_to_nine.c  (0) 2022.09.21