Want to convert these C++ to C??
(1)
Code:
#include <iostream.h>
#include <iomanip.h>
// Print out the first n Fibonacci numbers. n is assumed to be >= 1.
void fibo ( int n )
{
int current = 1; // The value of the (i)th fibonacci number
int next = 1; // The value of the (i+1)th fibonacci number
cout << "\n\n\t I \t Fibonacci(I) \n\t=====================" << endl;
for ( int i = 1; i <= n; i++ ) {
cout << "\t" << setw(3) << i << "\t\t"
<< setw(4) << current << endl;
int next2 = current + next;
current = next;
next = next2;
}
}
int main ( void )
{
int n; // The number of fibonacci numbers we will print
cout << "How many Fibonacci numbers do you want to compute? ";
cin >> n;
if ( n <= 0 )
cout << "The number should be positive." << endl;
else
fibo ( n );
return 0;
}
#include <iostream.h>
/* Get a positive integer from user */
int getPositive(void){
int current;
while( 1 ){
cout << "Please enter a positive integer: ";
cin >> current;
if (current > 0) return current;
cout << "It should be a positive integer";
}
}
/* Compute GCD */
int gcd (int dividend, int divisor)
{
int remaind;
remaind = dividend % divisor;
while (remaind != 0) {
dividend = divisor;
divisor = remaind;
remaind = dividend % divisor;
}
return divisor;
}
void main(void)
{
int dividend = getPositive();
int divisor = getPositive();
cout << "The GCD of " << dividend << " and " << divisor << " is "
<< gcd(dividend, divisor) << endl;
}