How to use function find the larger number in C Language

Program to use function find the larger number in C Language


#include <stdio.h>
int larger(int x, int y);
int main(void)
{
    int x, y;
    printf("Enter two number :");
    scanf("%d %d", &x, &y);
    printf("Larger number=%d\n", larger(x, y));
    return 0;
}
int larger(int x, int y)
{
    return x > y ? x : y;
}

Output


Enter two number :15
9
Larger number=15

How to use function parameters and arguments in C language

program to use function parameters and arguments in C language


#include <stdio.h>
void func(int a,int b);
int main()
{
    int x=10,y=20;
    func(x,y);
    printf("x=%d,y=%d\n",x,y);
    return 0;
}
void func(int a,int b)
{
    a++;
    b--;
    printf("a=%d, b=%d\n",a,b);
}

output


a=11, b=19
x=10,y=20

How to use function understand the return statement in C Language

Program to use function understand the return statement in C Language


#include lt&;stdio.h>
void selection(int age, float ht);
int main(void)
{
    int age;
    float ht;
    printf("Enter age and height: ");
    scanf("%d%f", &age, &ht);
    selection(age, ht);
    return 0;
}
void selection(int age, float ht)
{

    if (age > 25)
    {
        printf("age should be less than 25\n");
        return;
    }
    if (ht < 5)
    {
        printf("height should be more than 5\n");
        return;
    }
    printf("Selected\n");
}

Output


Enter age and height:19
Selected

How to use function find the sum of two numbers

Program to use function find the sum of two numbers


#include <stdio.h>
int sum(int x, int y); 
int main(void)
{
    int a = 10, b = 20, k;
    k = sum(a, b); /*Function call*/
    printf("%d\n", k);
    k = sum(4, 5); /*Function call*/
    printf("%d\n", k);
    k = sum(a + b, b * 2); /*function call*/
    printf("%d\n", k);
    return 0;
}
int sum(int x, int y)
{
    int s;
    s = x + y;
    return s;
}

Output


30
9
70

How to use find the sum of two numbers in C Language

Program to use find the sum of two numbers in C Language


#include <stdio.h>
int sum(int x, int y); /*Function declaration*/
int main()
{
    int a, b, s;
    printf("enter values for a and b :");
    scanf("%d %d", &a, &b);
    s = sum(a, b); /*Function call*/
    printf("sum of %d and %d is %d\n", a, b, s);
    return 0;
}
int sum(int x, int y) /*Function definition*/
{
    int s;
    s = x + y;
    return s;
}

Output


enter values for a and b :5
4
sum of 5 and 4 is 9

How to use larger number in C language

program to use larger number in C language


#include<stdio.h>
int larger(int x,int y);
int main()
{
    int x,y;
    printf("Enter two numbers : ");
    scanf("%d%d",&x,&y);
    printf("larger number=%d\n",larger(x,y));
    return 0;
}
int larger(int x,int y)
{
    return x>y?x:y;
}

output


Enter two numbers : 5
10
larger number=10

How to use return statement in C language

program to use return statement in C language


#include<stdio.h>
void selection(int age,float ht);
int main()
{
    int age;
    float ht;
    printf("Enter age and height : ");
    scanf("%d%f",&age,&ht);
    selection(age,ht);
    return 0;
}
void selection(int age,float ht)
{
    if(age>25)
    {
        printf("Age should be less than 25\n");
        return;
    }
    if(ht<5)
    {
        printf("Height should be more than 5\n");
        return;
    }
    printf("selected\n");
}

output


Enter age and height : 24
5
selected

How to use JavaScript Array unshift()

Program to use JavaScript Array unshift() method


let a = [8,10,12,14,16,18,20];
let b = a.unshift(2,4,6);

console.log(a);
console.log(b);

Output


[
    2,  4,  6,  8, 10,
   12, 14, 16, 18, 20
 ]
 10

Steps Description

  1. Declare two variable a and b
  2. Initialize two variable with value of array a = [8,10,12,14,16,18,20] and b = a.unshift(2,4,6)
  3. Array unshift() method appends one or more elements to the beginning of an array and returns the length of the new array.
  4. The value of b variable is displayed with the help of console.log inbuilt function

Program to use JavaScript Array unshift() method


let c = [ 'Cat', 'Dog', 'Tiger', 'Lion'];
let d = c.unshift('Elephant', 'Bear');

console.log(c);
console.log(d);

Output


[ 'Elephant', 'Bear', 'Cat', 'Dog', 'Tiger', 'Lion' ]
6

Steps Description

  1. Declare two variable c and d
  2. Initialize two variable with value of array c = [ 'Cat', 'Dog', 'Tiger', 'Lion'] and d = c.unshift('Elephant', 'Bear')
  3. Array unshift() method appends one or more elements to the beginning of an array and returns the length of the new array.
  4. The value of d variable is displayed with the help of console.log inbuilt function

How to use JavaScript Array toString()

Program to use JavaScript Array toString() method


let a = [1, 2, 'Apple', '3', '7', 'Banana'];
let b = a.toString();


console.log(b);

Output


1,2,Apple,3,7,Banana

Steps Description

  1. Declare two variable a and b
  2. Initialize two variable with value of array a = [1, 2, 'Apple', '3', '7', 'Banana'] and b = a.toString()
  3. Array toString() method converts the array to a string.
  4. The value of b variable is displayed with the help of console.log inbuilt function