Found 34494 Articles for Programming

C++ Program to Find Factorial of Large Numbers

karthikeya Boyini
Updated on 26-Jun-2020 08:40:22

1K+ Views

The following is an example to find the factorial.Example#include using namespace std; int fact(unsigned long long int n) {    if (n == 0 || n == 1)    return 1;    else    return n * fact(n - 1); } int main() {    unsigned long long int n;    coutn;    cout

C++ Program to Find Fibonacci Numbers using Recursion

Samual Sam
Updated on 06-Sep-2023 21:11:54

52K+ Views

The following is an example of fibonacci series using recursion.Example Live Demo#include using namespace std; int fib(int x) {    if((x==1)||(x==0)) {       return(x);    }else {       return(fib(x-1)+fib(x-2));    } } int main() {    int x , i=0;    cout x;    cout

Pointer to an Array in C

Samual Sam
Updated on 14-Sep-2023 21:15:58

26K+ Views

Pointers are variables which stores the address of another variable. When we allocate memory to a variable, pointer points to the address of the variable. Unary operator (*) is used to declare a variable and it returns the address of the allocated memory. Pointers to an array points the address of memory block of an array variable.The following is the syntax of array pointers.datatype *variable_name[size];Here, datatype − The datatype of variable like int, char, float, etc.variable_name − This is the name of variable given by user.size − The size of array variable.The following is an example of array pointers.Example Live Demo#include ... Read More

return statement vs exit() in main() C++

karthikeya Boyini
Updated on 26-Jun-2020 08:44:19

1K+ Views

return statementThe return statement terminates the execution of function and it returns the control to the calling function. It calls the constructor as well as the destructor. It returns an integer value for “int main()”.The following is the syntax of return statement.return expression;Here,expression − The expression or any value to be returned.The following is an example of return statement.Example Live Demo#include using namespace std; class Method {    public:    Method() {       cout

C function to Swap strings

Samual Sam
Updated on 26-Jun-2020 08:44:51

597 Views

The following is an example to swap strings.Example Live Demo#include #include int main() {    char st1[] = "My 1st string";    char st2[] = "My 2nd string";    char swap;    int i = 0;    while(st1[i] != '\0') {       swap = st1[i];       st1[i] = st2[i];       st2[i] = swap;       i++;    }    printf("After swapping s1 : %s", st1);    printf("After swapping s2 : %s", st2);    return 0; }OutputAfter swapping s1 : My 2nd string After swapping s2 : My 1st stringIn the above program, two ... Read More

Initialization of static variables in C

karthikeya Boyini
Updated on 26-Jun-2020 08:45:18

4K+ Views

When static keyword is used, variable or data members or functions can not be modified again. It is allocated for the lifetime of program. Static functions can be called directly by using class name.Static variables are initialized only once. Compiler persist the variable till the end of the program. Static variable can be defined inside or outside the function. They are local to the block. The default value of static variable is zero. The static variables are alive till the execution of the program.Here is the syntax of static variables in C language, static datatype variable_name = value;Here, datatype − ... Read More

Return values of printf() and scanf() in C

Samual Sam
Updated on 26-Jun-2020 08:25:18

11K+ Views

The printf() and scanf() functions are required for output and input respectively in C. Both of these functions are library functions and are defined in the stdio.h header file.Details about the return values of the printf() and scanf() functions are given as follows −The printf() functionThe printf() function is used for printing the output. It returns the number of characters that are printed. If there is some error then it returns a negative value.A program that demonstrates this is as follows −Example Live Demo#include int main(){    char str[] = "THE SKY IS BLUE";    printf("The value returned ... Read More

Return type of getchar(), fgetc() and getc() in C

karthikeya Boyini
Updated on 26-Jun-2020 08:30:45

2K+ Views

Details about getchar(), fgetc() and getc() functions in C programming are given as follows −The getchar() functionThe getchar() function obtains a character from stdin. It returns the character that was read in the form of an integer or EOF if an error occurs.A program that demonstrates this is as follows −Example Live Demo#include int main (){    int i;    printf("Enter a character: ");    i = getchar();    printf("The character entered is: ");    putchar(i);    return(0); }OutputThe output of the above program is as follows −Enter a character: G The character entered is: GNow ... Read More

Default values of static variables in C

Samual Sam
Updated on 26-Jun-2020 08:31:52

3K+ Views

When static keyword is used, variable or data members or functions can not be modified again. It is allocated for the lifetime of program. Static functions can be called directly by using class name.Static variables are initialized only once. Compiler persist the variable till the end of the program. Static variable can be defined inside or outside the function. They are local to the block. The default value of static variable is zero. The static variables are alive till the execution of the program.Here is the syntax of static variables in C language, static datatype variable_name;Here, datatype − The datatype ... Read More

pow() function in C

karthikeya Boyini
Updated on 26-Jun-2020 08:33:04

7K+ Views

The function pow() is used to calculate the power raised to the base value. It takes two arguments. It returns the power raised to the base value. It is declared in “math.h” header file.Here is the syntax of pow() in C language, double pow(double val1, double val2);Here, val1 − The base value whose power is to be calculated.val2 − The power value.Here is an example of pow() in C language, Example#include #include int main() {    double x = 5.5;    double y = 4.0;    double p;    p = pow(x, y);    printf("The value : %lf", p);   ... Read More

Advertisements