-1

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 by qqwushi12345: n/a

4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by Allophyl
0

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

0

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

Edited by qqwushi12345: n/a

0

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

'return 0;'
to signify proper program termination

0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.