Sunday, August 2, 2009

Question in C programming answer fast please i will give points?

#include %26lt;stdio.h%26gt;





#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);





}





1. What does the program do ?


2. What will the output be ? (if the user enters the following input: 120 for num1 and 24 for num2).


3. How many cycles will be executed for this input ?

Question in C programming answer fast please i will give points?
1.This program finds the GCD (greatest common divisor)


2. 24 is the result for the provided params (120, 24). Notice that 24 divides 120 and 24.


3. I don't know, it depends on the numbers, but they are O(num1)
Reply:did your teacher give you this program. it doesn't show what


GetInteger() does????





The program reads two numbers in. Then finds the remainder into Temp and checks if this is 0 if it is 0 then it breaks and quits the program.





Then it just takes Num2 and puts it into num1 (so you loose 120)


then puts temp into num2 which I'm guessing is 0.


cycles? one
Reply:It calculates the remainders of the division num1/num2. If there are no remainders it prints number 2. If there are remainders, it will set num1 equal to num2, then num2 equal to the amount of remainders then start to process all over again until there are no remainders left.





Run it.





As many as it takes until there are no remainders.
Reply:1. It is impossible to say without the definition of GetInteger() and the contents of genlib.h and simpio.h. On the surface it doesn't appear to do anything useful.





2. If you enter 120 and 24 the output is 24.





3. If by "cycles" you mean times through the loop, the answer is either 0 or 1 depending on how you count. If by "cycles" you mean "machine cycles" the answer depends on too many factors to be described here.





In short it's a bad question.
Reply:1. it devides the positive integers


2. the output will be 5.


3. 4 cycle will be exicuted

potential breakup song

No comments:

Post a Comment