I tried to do this:
#include <stdio.h >
int main(void) {
int common = 0;
int num1;
int num2;
int big;
int small;
int i;
printf("Enter the first number : ");
scanf("%d", &num1);
printf("Enter the second number : ");
scanf("%d", &num2);
if (num1 <= num2) {
num1 = small;
num2 = big;
}
else{
num1 = big;
num2 = small;
}
for (i = small ; ; i )
{
}
I don't know what is meant by to 1 do. I'm beginner in algorithms
but I think it means i isn't?
CodePudding user response:
The algorithm says to count from small
down to 1
. So the repetition should be i--
, not i
. Use i >= 1
as the repetition condition to keep looping until you get to 1
.
for (i = small; i >= 1; i--)