int pow (int a, int b)
{
if (b==0) return 1;
else return a*pow(a,b-1);
}
a XOR b is a^b in C language
Use the following function: int gcd (int a, int b) { while (b != 0) { a %= b; a ^= b ^= a ^= b; } return a; } Note that a ^= b ^= a ^= b is an efficient method of swapping two values.
for two positive integers: public static int gcd(int i1, int i2) { // using Euclid's algorithm int a=i1, b=i2, temp; while (b!=0) { temp=b; b=a%temp; a=temp; } return a; }
The language was called the "C" language because it was a kind of successor of the "B" language.
#include <stdio.h> int main() { int a, b,i,ans; printf("Enter a and b\t"); scanf("%d %d",&a,&b); ans=1; for(i=0;i<b;i++) ans=ans*a; printf("%d to the power %d = %d",a,b,ans); return 0; }
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.
a XOR b is a^b in C language
B. L. Meek has written: 'Fortran, PL/I, and the algols' -- subject(s): ALGOL (Computer program language), FORTRAN (Computer program language), PL/I (Computer program language)
Use the following function: int gcd (int a, int b) { while (b != 0) { a %= b; a ^= b ^= a ^= b; } return a; } Note that a ^= b ^= a ^= b is an efficient method of swapping two values.
for two positive integers: public static int gcd(int i1, int i2) { // using Euclid's algorithm int a=i1, b=i2, temp; while (b!=0) { temp=b; b=a%temp; a=temp; } return a; }
The language was called the "C" language because it was a kind of successor of the "B" language.
biggest3 (a,b,c) = biggest2 (a, biggest2 (b,c))
K. Lano has written: 'Specification in B' -- subject(s): B (Computer program language)
B. Legrand has written: 'APL' -- subject(s): APL (Computer program language), Problems, exercises
(ab)*b
It's pow from math.h
You can do it simpler just by using preprocessor directive#include void main(){int a, b;cout > a;cout > b;cout b;for (int i =1; i