Introduction to Programming (22C:16, 22C:106)

Homework 7: Due Thursday, 4/03/97

Solution:

 
Problem 1 :

#include <iostream.h>

int main() { 

	int a,b,c,d;
	int x,y,z;

	cout << " Enter the values of A, B , C and D : ";
	cin >> a >> b >> c >> d;

	if ( ( a == 0) || ( b == 0) || ( c == 0 ) || ( d == 0 ) ) { 
		cout << " There are infinite solutions " ;
		return 0;
		}
	x = 0;
	while ( x <= d/a) { 
		y = 0;
		while ( y <= (d-a*x)/b ) { 
			if ( (d-a*x-b*y) %c == 0) { 
				z = ( d - a * x - b * y ) / c;
				if ( z > 0 ) 
					cout << x << y << z << endl;
  			}
		y = y + 1;
		}
	x = x + 1;
	}
return 0;
}

Problem 2 :

#include <iostream.h>
#include "bigint.h"

int main() {

	BigInt number;
	BigInt root;  

	cout << " Enter the number : ";
	cin >> number;

	root = number/2;
	while (root*root - number > 1) 
	root = (root + n/root)/2;
	cout << " The nearest root is " << root << endl;

	return 0;
}