Why is it only executed once the repeat is turned?

Asked 2 years ago, Updated 2 years ago, 48 views

#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>

int main(void) {
    int num1;
    int num2;
    printf("Enter integer 1 : ");
    int a = scanf("%d", &num1);
    printf("Enter integer 2 : ");
    int b = scanf("%d", &num2);

    while (1)
    {        
        if (num1 >= num2)
        {
            if (num1 % num2 == 0) ;
                printf("a");
                printf("Maximum number of pledges: %d",num2);
                break;
            }
            else {
                num1 = num2;
                num2 = num1 % num2;
            }
        }
        else if (num1 < num2)
        {
            if (num2 % num1 == 0) {
                printf("Maximum number of pledges: %d", num1);
                break;
            }
            else {
                num2 = num1;
                num1 = num2 % num1;
            }
        }
    }

    return 0;
}

If you put 50 to 10 in the whole number, it'll come out right 4836 If you put it in like this, the printf itself won't come out

c c++ error

2022-09-20 17:47

1 Answers

You have to debug these things yourself to improve your skills.

I think you're using a visual studio, so learn how to breakpoint (f9), how to run it in debugging mode (f5), and how to run it in one line (f10).


2022-09-20 17:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.