0
how would I continue to run the program over again without closing and starting it up again?
#include <stdio.h> int greatestCommonDivisor(int m, int n) //This function implements the Euclidian Algorithm { int r; /* Check For Proper Input */ if ((m == 0) && (n == 0)) { printf("Bye"); return 0; } else if ((m <= 0) || (n <= 0)) { printf("Wrong input. "); printf("Please enter positive integers. "); return 0; } do { r = m % n; if (r == 0) break; m = n; n = r; } while (0); return n; } int main(void) { int num1, num2; printf("Please enter two numbers: "); scanf("%d %d", &num1, &num2); int gcd = greatestCommonDivisor(num1, num2); if (gcd >= 1) { printf("The GCD of %d and %d is %d\n", num1, num2, gcd); } getchar(); return 0; }
3 Antworten
0
#include <stdio.h>
int greatestCommonDivisor(int m, int n)
//This function implements the Euclidian Algorithm
{
int r;
/* Check For Proper Input */
if ((m == 0) && (n == 0))
{
printf("Bye");
return 0;
}
else if ((m <= 0) || (n <= 0))
{
printf("Wrong input. ");
printf("Please enter positive integers. ");
return 0;
}
do
{
r = m % n;
if (r == 0)
break;
m = n;
n = r;
} while (0);
return n;
}
int main(void)
{
char repeat;
do {
int num1, num2;
printf("Please enter two numbers: ");
scanf("%d %d", &num1, &num2);
int gcd = greatestCommonDivisor(num1, num2);
if (gcd >= 1)
{
printf("The GCD of %d and %d is %d\n", num1, num2, gcd);
}
getchar();
printf("Exit?: y/n");
scanf("%c", &repeat);
}while(repeat != 'y');
return 0;
}
0
well without having to say repeat.. it keeps going until the user enter 0 0..
0
How about this?:
do {
int num1, num2;
printf("Please enter two numbers (other than 0): ");
scanf("%d %d", &num1, &num2);
if(num1 == 0 || num2 == 0)
return 0;
int gcd = greatestCommonDivisor(num1, num2);
if (gcd >= 1)
{
printf("The GCD of %d and %d is %d\n", num1, num2, gcd);
}
getchar();
}while(true);
return 0;