How to use arithmetic calculations on integers in C language

program to use arithmetic calculations on integers in C language


#include<stdio.h>
int main()
{
    char op;
    int a,b;
    printf("Enter number,operator and another number : ");
    scanf("%d%c%d",&a,&op,&b);
    switch (op)
    {
    case '+':
        printf("Result=%d\n",a+b);
        break;
    case '-':
    printf("Result=%d\n",a-b);
    break;
    case '*':
    printf("Result=%d\n",a*b);
    break;
    case '/':
    printf("Result=%d\n",a/b);
    break;
    case '%':
    printf("Result=%d\n",a%b);
    break;
    default:
     printf("Enter valid operator\n");
    }
    return 0;
}

output


Enter number,operator and another number : 2+3
Result=5

How to use switch with break statement in C language

program to use switch with break 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("Wrong choice\n");
    }
    return 0;
}

output


Enter your choice : 2
second

How to use switch control statement in C language

program to use switch control ststement in C language


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

output


Enter your choice : 1
first
second
third
Wrong choice

How to use find whether a number is even or odd in C language

program to use find whether a number is even or odd in C language


#include <stdio.h>
int main()
{
    int n;
    printf("Enter a number : ");
    scanf("%d", &n);
    if (n % 2 == 0)
    {
        goto even;
    }
    else
    {
        goto odd;
    }
even:
{
    printf("Number is even\n");
    goto end;
}
odd:
{
    printf("Number is odd\n");
    goto end;
}
end:
    printf("\n");
    return 0;
}

output


Enter a number : 16
Number is even

How to use whether a number is prime or not in C Language

Program to use whether a number is prime or not in C Language


#include <stdio.h>
#include <math.h>
int main()
{
    int i, n;
    printf("enter a number : ");
    scanf("%d", &n);
    for (i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            break;
        }
    }
    if (i > sqrt(n))
    {
        printf("%d is prime\n", n);
    }
    else
    {
        printf("%d is not prime\n", n);
    }
    return 0;
}

output


enter a number :
23 is prime

How to use Array push() JavaScript Language

Program to use Array Push() Method JavaScript Language


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

Output


[ 1, 2, 3, 4, 5 ]

Steps Description

  1. Declare variable a
  2. Initialise variable a with value of array a = [1, 2, 3]
  3. The push() method of an array adds one or more elements to the end of the array.
  4. The value of a variable is displayed with the help of console.log inbuilt function

Program to use Array Push() Method JavaScript Language


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

Output


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

Steps Description

  1. Declare variable b
  2. Initialise variable b with value of array b = ['Cat','Dog','Tiger']
  3. The push() method of an array adds one or more elements to the end of the array.
  4. The value of b variable is displayed with the help of console.log inbuilt function