I'm assuming you are asking about an Array with {1,2,3,4} then the length would be the number of elements: 4.
int recursiveNFactorial (int n) { if (n < 2) return 1; if (n == 2) return n; else return n * recursiveNFactorial (n - 1); } int iterativeNFactorial (int n) { int result = 2; if (n < 2) return 1; while (n > 2) result *= n--; return result; }
Java solutionpublic static final int[] getMiddle(final int[] a, final int[] b) {return new int[] {a[1], b[1]};}C solution void getMiddle(const int a[], const int b[], int ret[]) {ret[0] = a[1];ret[1] = b[1];}
int num1 = 1; int num2 = 50; int addition = num1 + num2;
C++: #include <iostream> int main() { for(int i = 5; i > 0; --i) { for(int j = i; j <= 5; ++j) { std::cout << j << ' '; } } return 0; }
Assume your numbers are into an array. Then write any user-defined function implementing any kind of sorting. I am giving example of bubble sort.void bubble(int a[],int n){int i,j,t;for(i=n-2;i>=0;i--){for(j=0;ja[j+1]){t=a[j];a[j]=a[j+1];a[j+1]=t;}}}}
int a = 1 + 2; ---------- int a = 1; int b = 2; a += b;
In Java:System.out.println("Even numbers")for (int i = 2; i
I assume that Int(x) represents the integer part of the number x. This is not a function since it is a many-to-many mapping. If it is a real valued mapping, the domain is at most [-1, 1] When x = -1 or x = 1, then y is in [0, 1); When x is in (-1, 1), then y is in [1, sqrt(2)).
int recursiveNFactorial (int n) { if (n < 2) return 1; if (n == 2) return n; else return n * recursiveNFactorial (n - 1); } int iterativeNFactorial (int n) { int result = 2; if (n < 2) return 1; while (n > 2) result *= n--; return result; }
Java solutionpublic static final int[] getMiddle(final int[] a, final int[] b) {return new int[] {a[1], b[1]};}C solution void getMiddle(const int a[], const int b[], int ret[]) {ret[0] = a[1];ret[1] = b[1];}
CCW rotation 1-3-4-2 / 1 ex, 1 int / 3 int, 3 ex / 4 int, 4 ex / 2 ex, 2 int
#include <iostream> bool isPrime(int p) { if( p<=1 ( p>2 && p%2==0 ))return( false );int max = (int)sqrt(( double ) p ) + 1; for( int i=3; i<=max; i+=2 )if( p%i==0 )return( false );return( true ); } int main() { for( int i=1; i<100; i>2?i+=2:++i )if( isPrime(i) )std::cout << i << std::endl;return( 0 ); }
Value range.Tipical v.r. for short int: -2^15 .. 2^15-1Tipical v.r. for int: -2^15 .. 2^15-1 or -2^31 .. 2^31-1Tipical v.r. for long int: -2^31 .. 2^31-1 or -2^63 .. 2^63-1Tipical v.r. for long long int: -2^63 .. 2^63-1Of course all of these are platform-dependent.
#include <iostream> bool isPrime(int p) {if( p<=1 ( p>2 && p%2==0 ))return( false );int max = (int)sqrt(( double ) p ) + 1; for( int i=3; i<=max; i+=2 )if( p%i==0 )return( false );return( true ); } int main() {for( int i=1; i<5000; i>2?i+=2:++i )if( isPrime(i) )std::cout << i << std::endl;return( 0 ); }
int num1 = 1; int num2 = 50; int addition = num1 + num2;
int a = 1; int b = 2; int c = a + b; // Sum
int divide1(int a,int b) { int t=1; while(b*t<=a) { t++; } return t-1; }