void swap(int &x, int &y) { x ^= y ^= x; } - or - void swap(int &x, int &y) { int t = x; x = y; y = t; }
int x;float x;char x;double x;long x;long long x;short x;unsigned int x;unsigned float x;unsigned double x;signed char x;unsigned long x;unsigned long long x;int *x;float *x;char *x;double *x;long *x;long long *x;int x[100];typedef struct rect {int left;int top;int right;int bottom;};int main(int argv, char* argc[]) {return 0;}That enough for you?Well, these are definitions, declarations are like these:extern char x;int main (int argc, char **argv);
No such thing, pick one ot the three: static int x; extern int x; int x;
public int sum(int[] x) {int sum = 0;for(int i : x) {sum += i;}return sum;}public int average(int[] x) {// Note that this returns an int, truncating any decimalreturn sum(x) / x.length;}
you make a function yourself For example : int cube (int input); int main (void) { int x = 2; printf(x is %d\n",x); x = cube (x); printf("x is %d\n",x); return 0; } int cube (int input) { int output = input * input *input ; return output; } the output will be : x is 2 x is 8
In algebra, x is the unknown for which you need the value.
#include<iostream> void byref(int& x){x*=x;} void byval(int x){x*=x;} int main() { int y = 5; byval(y); // y 25 return(0); }
static int x=3;
In BASIC, this could be as simple as: 10 Input X 20 Input Y 30 Z=X+Y 40 Print X;" + ";Y;" = ";Z 50 END In JAVA... /** * A simple calculator that adds, subtracts, multiplies, and divides. * Written in Java by: AustinDoggie */ public class Calculator() { public Calculator() { // don't really have to do anything here } public int add(int x, int y) { int z = x + y; // add two numbers return z; // and return it } public int subtract(int x, int y) { int z = x - y; // subtract two number return z; // and return it } public int multiply(int x, int y) { int z = x*y; // multiply two number return z; // and return it } public int divide(int x, int y) { int z = x/y; // divide two numbers return z; // and return the result } } Hope that helps.
#include <cstdio> int fact(int x); int main() { int x, total; printf("Enter a number: "); scanf("%d", &x); total = fact(x); printf("The factorial of %d is %d", x, total); char wait; scanf("%s", wait); return 0; } int fact(int x) { if(x == 1) { return 1; } return fact(x - 1) * x; }
In C++: #include <iostream> using namespace std; int fact(int x); int main() { int x, total; cout << "Enter a number: "; cin >> x; total = fact(x); cout << "The factorial of " << x << " is: " << total << endl; char wait; cin >> wait; return 0; } int fact(int x) { if(x == 1) { return 1; } return fact(x - 1) * x; }
Use integration by parts: int [ln(x)] = xln(x) - int(x/x) = xln(x) - x + c