I need to write an iterative function of the program I wrote as recursive.

I am a total rookie at this c programing game. I got my program working with a recursive function and it does what it is suppose to do.

Example: 6 and 15 = 3 ; 15 and 22 =1

I gave it a shot writing the program without the recursive function but it doesnt compute properly.

Can someone help me out with this.

Code:/* HERE IS MY RECURSIVE PROGRAM IT WORKS PERFECTLY /* /* #include <stdio.h> */ /* int gcd (int a, int b); */ /* int main() */ /* { */ /* int a=0; */ /* int b=0; */ /* printf(" This program will compute greatest common divisor of two integers. \n"); */ /* printf("Please enter two integers: \n\n"); */ /* scanf("%d", &a); */ /* scanf("%d", &b); */ /* printf("\n The greatest common denominator of %d and %d is %d \n", a, b, gcd(a,b)); */ /* return 0; */ /* } */ /* Recursive Function */ /* int gcd (int a,int b)*/ /* { */ /* int r; */ /* if ((r=a%b) == 0) */ /* return b; */ /* else */ /* return gcd(b, r); */ /* } */ /* HERE IS MY ATTEMPT TO DO THIS ITERATIVE FUNCTION */ #include <stdio.h> int gcd (int a, int b); int main() { int a=0; int b=0; int r=0; printf(" This program will compute greatest common divisor of two integers. \n"); printf("Please enter two integers: \n\n"); scanf("%d", &a); scanf("%d", &b); r=(a%b); printf("\n The greatest common denominator of %d and %d is %d \n", a, b, r); return 0; }