Chat with our AI personalities
I will explain in the easiest way the difference between the function and recursive function in C language. Simple Answer is argument of the function is differ but in the recursive function it is same:) Explanation: Function int function(int,int)// function declaration main() { int n; ...... ...... n=function(a,b); } int function(int c,int d) { ...... ...... ...... } recursive Function: int recursive(int,int)// recursive Function declaration main() { int n; ..... ..... ..... ..... n=recursive(a,b); } int recursive(int a,int b) { ..... .... .... .... } Carefully see, In the recursive Function the function arguments are same.
Code example:/* ******************************************************************************** * FUNCTION: bIsAPrime ******************************************************************************** * AUTHORS: * Flaun * * DESCRIPTION: * Finds if a given number is a prime number. * * PARAMETERS: * uiTestNumber: An unsigned integer to test. * * RETURNS: * bTRUE or bFALSE ******************************************************************************** */ #define bTRUE 1 #define bFALSE 0 #define iNO_REMAINDER 0 #define bIS_ODD(uiNumber) ((uiNumber) & 1) typedef int BOOL BOOL bIsAPrime( unsigned int uiTestNumber) { /* 4 is the first non prime number. */ if(uiTestNumber > 3) { /* The only even prime number is 2. */ if(!bIS_ODD(uiTestNumber)) { return bFALSE; } else { /* The only numbers left to divide against are 3, 5 and 7. */ /* All numbers that are divisible by a number > 7 are divisible */ /* by a number < 8. */ unsigned int uiDivisor = 0; for(uiDivisor = 3; uiDivisor
i=0; do{ i++; }while(i<10);
whatever the variables we declare in function signature to receive the arguments at the calling that are known as parameters.. e.g. int sum(int a,int b); here a & b are known as parameters.....
// The "LCMTest" class. import hsa.*; public class LCMTestDanyalM { // Place your lowestCommonMultiple code here public static int lowestCommonMultiple (int firstNumber, int secondNumber) { /// int product = 1; // int limit = firstNumber * secondNumber; for (int count = 1 ; ; count++) { if (count % firstNumber 0) { return count; } } } // Do not modify the code below public static void main (String [] args) { Console c = new Console (); final int NO_OF_TEST_CASES = 1000000; // maximum of 1000000 int [] first = new int [NO_OF_TEST_CASES]; int [] second = new int [NO_OF_TEST_CASES]; int [] LCM = new int [NO_OF_TEST_CASES]; c.println ("Loading the data..."); TextInputFile inFile = new TextInputFile ("lcmdata.txt"); int index = 0; while (!inFile.eof () && index < first.length) { first [index] = inFile.readInt (); second [index] = inFile.readInt (); LCM [index] = inFile.readInt (); index++; } inFile.close (); // Testing the correctness and speed c.println ("Start Timing"); long startTime = System.currentTimeMillis (); for (int nextTest = 0 ; nextTest < first.length ; nextTest++) { int studentLCM = lowestCommonMultiple (first [nextTest], second [nextTest]); if (studentLCM != LCM [nextTest]) { c.println ("Incorrect: For " + first [nextTest] + " and " + second [nextTest] + " you got " + studentLCM + " for the lowest common mulitple," + "\nbut the answer should be: " + LCM [nextTest]); break; } } long endTime = System.currentTimeMillis (); c.print ("Total Time: "); c.println ((endTime - startTime), 20); c.println ("Program Complete"); } // main method } // Perfect class