How to use switch control statement in C Language

Program to use switch control statement in C Language


#include<stdio.h>
int main()
{
    int choice;
    printf("Enter your choice : ");
    scanf("%d",&choice);
    switch(choice)
    {
        case 1:
        {
            printf("first\n");
            break;
        }
        case 2:
        {
            printf("second\n");
            break;
        }
        case 3:
        {
            printf("third\n");
            break;
        }
        default:
        {
            printf("woring choice\n");
        }
    }
    return 0;
}  

Output


Enter your choice : 3
third

How to use sum in C language

program to use sum C language


#include<stdio.h>
int sum(int x, int y);   /*Function declaration*/
int main()
{
    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)  /*Function definition*/
{
    int s;
    s=x+y;
    return s;
}

output


30
9
70

How to use sum and average in C language


#include <stdio.h>
int main()
{
    int i = 1, n, sum = 0;
    float avg;
    printf("enter 3 positive number : \n");
    while (i <= 3)
    {
        printf("enter number %d : ", i);
        scanf("%d", &n);
        if (n < 0)
        {
            printf("enter only positive numbers\n");
            continue;
        }
        sum += n;
        i++;
    }
    avg = sum / 10.0;
    printf("sum=%d avg=%.2f\n", sum, avg);
    return 0;
}

Output


enter number : 1 2
enter number : 2 4 
enter number : 3 5
sum=11 avg=1.10

How to use sum of two numbers is functions in C language

program to use sum of two numbers is functions in C language

इस program मैं दो value को जोड़ रहा है


#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 : 12
6
sum of 12 and 6 is 18

How to use grade of mark in C language

program to use grade of mark in C language


#include <stdio.h>
int main()
{
    float m1, m2, m3, m4, total, per;
    char grade;
    printf("enter marks of 4 subjects : ");
    scanf("%f%f%f%f", &m1, &m2, &m3, &m4);
    total = m1 + m2 + m3 + m4;
    per = total / 4;
    if (per >= 85)
    {
        grade = 'A';
    }
    else if (per >= 70)
    {
        grade = 'B';
    }
    else if (per >= 55)
    {
        grade = 'c';
    }
    else if (per >= 40)
    {
        grade = 'D';
    }
    else
    {
        grade = 'E';
    }
    printf("percentage is %f,grade is %c\n", per, grade);
    return 0;
}

output


enter marks of 4 subjects : 80
95
70
60
percentage is 76.250000,grade is B

How to use JavaScript Object keys()

Program to use JavaScript Object keys() method


let player = {
    name: "Cristiano Ronaldo",
    age: "38",
    game: "football",

};

let a = Object.keys(player);
console.log(a);

Output


[ 'name', 'age', 'game' ]

Steps Description

  1. Declare two variable Object variable and variable player and a
  2. Initialize two variable Object variable and variable player and a with value of Object player = {name: "Cristiano Ronaldo",age: "38",game: "football",}; and a
  3. The Object key() method outputs the given object into an array.
  4. The value of a variable is displayed with the help of console.log inbuilt function

How to use JavaScript Array join()

Program to use JavaScript Array join() method


let a = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant'];
let b = a.join(" ");
console.log(b);

Output


Cat Dog Tiger Lion Elephant

Steps Description

  1. Declare two variable a and b
  2. Initialize two variable a and b with value of array a = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant'] and b = a.join(" ")
  3. The array join() method joins the given statement to all elements of the array.
  4. The value of b variable is displayed with the help of console.log inbuilt function

Program to use JavaScript Array join() method


let c = ['Good Morning', 'Good Afternoon', 'Good Evening', 'Good Night'];
let d = c.join(" * ");
console.log(d);

Output


Good Morning * Good Afternoon * Good Evening * Good Night

Steps Description

  1. Declare two variable c and d
  2. Initialize two variable c and d with value of array c = ['Good Morning', 'Good Afternoon', 'Good Evening', 'Good Night'] and d = c.join(" * ")
  3. The array join() method joins the given statement to all elements of the array.
  4. The value of d variable is displayed with the help of console.log inbuilt function

How to use JavaScript Array isArray()

Program to use JavaScript Array isArray() method


let a = [1,2,3,4,5];
let b = Array.isArray(a);
console.log(b);

Output


true

Steps Description

  1. Declare two variable a and b
  2. Initialize two variable a and b with value of array a = [1,2,3,4,5] and b = Array.isArray(a)
  3. Array isArray() method checks whether Array is or not and returns a boolean value.
  4. The value of b variable is displayed with the help of console.log inbuilt function

Program to use JavaScript Array isArray() method


let c = 'Hello World';
let d = Array.isArray(c);
console.log(d);

Output


false

Steps Description

  1. Declare two variable c and d
  2. Initialize two variable c and d with value of string c = 'Hello World' and d = Array.isArray(c)
  3. Array isArray() method checks whether Array is or not and returns a boolean value.
  4. The value of d variable is displayed with the help of console.log inbuilt function