Can any body tell me what the below code does? The code is written in C++ language.

-------------------------------------------------------------------------------------

#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
main(){
	int num1, num2, temp;

	printf (“Enter a positive integer:  \n”);
	num1=GetInteger();
	printf (“Enter a positive integer:  \n”);
	num2=GetInteger();
	while (TRUE){
		temp=num1%num2;
		if (temp==0) break;
		num1=num2;
		num2=temp;
	}
	printf (“The result is: %d “, num2);
}

-------------------------------------------------------------------------------------

What does this program do? thank you. The code is written in C++ language.

Edited 6 Years Ago by qqwushi12345: n/a

fist of all is dis c++ or java.......or a silly combination of both.based on syntax i do know its supposed to accept two numbers and get their remainder when divided.if ders no remainder then the numbers are equal

But when there is no remainder the result is the 2nd number?

Edited 6 Years Ago by qqwushi12345: n/a

i presume ur printf functions are defined in the headers that you included.and you forgot to

'return 0;'
to signify proper program termination

first of all printf is not a C++ thing lol. inless thats included with your header.

cout << "enter a number: ";

is a better way of doing it.

and the calcualation doesnt make much sence. it did all the way upto when it made num1=num2.

its looking for a remander. then checking if the remander is == 0

but the next part doesnt make a lot of scence. i mean its not really doing anything :P.

Looks like the euclidean algorithm to me. It computes the Greatest Common Divisor of two numbers.

This article has been dead for over six months. Start a new discussion instead.