Leap Year In JavaScript

Leap Year


let year = 2100;
// Define variable year and initialize value
{
  if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
    // three conditions to find leap year
    // The number which is divided by 4 or 400 is a leap year.
    // The number that divided by 100 is not zero is leap year

    console.log(year + " is leap year");
  } else {
    console.log(year + " is not leap year");
  }
}

Output


2100 is not leap year

How To Define Area in Switch Case in JavaScript

Define Area in switch case


let area = "circle";
let PI = 3.142,
  l = 9,
  b = 7,
  r = 6;
switch (area) {
  case "circle":
    console.log("Area of the circle is : " + PI * r ** 2);
    break;
  case "triangle":
    console.log("Area of the triangle is : " + (l * b) / 2);
    break;
  case "rectangle":
    break;
    console.log("Area of the rectangle is : " + l * b);
  default:
    console.log("please enter valid data");
}

Output


Area of the circle is : 113.112

How to use prime number is not prime in c language

program to use prime number is not prime 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;
        }
        printf("i=%d\n", i);
        printf("n=%d\n", n);
    }
    if (i > sqrt(n))
    {
        printf("%d is prime\n", n);
    }
    else
    {
        printf("%d is not prime\n", n);
    }
    return 0;
}

output


Enter a number : 7
i=2
n=7
7 is prime

output


Enter a number : 4
4 is not prime

How to use sum and average in c language

program to use sum and average in c language


#include<stdio.h>
int main()
{
    int i=1,n,sum=0;
    float avg;
    printf("Enter 10 positive numbers : \n");
    while(i<=10)
    {
        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=%f\n",sum,avg);
    return 0;
}

output


Enter 10 positive numbers : 
Enter number 1 : 2
Enter number 2 : 4
Enter number 3 : 5
Enter number 4 : 6
Enter number 5 : 9
Enter number 6 : 4
Enter number 7 : 3
Enter number 8 : 1
Enter number 9 : 8
Enter number 10 : 5
sum=47 avg=4.700000

How to use factorial number in C Language

program to use factorial number in C Language


#include <stdio.h>
int main()
{
    int n, num;
    long fact = 1;
    printf("enter a number : ");
    scanf("%d", &n);
    num = n;
    if (n < 0)
    {
        printf("no factorial of negative number\n");
    }
    else
    {
        while (n > 1)
        {
            fact *= n;
            n--;
        }
        printf("factorial of %d=%d\n", num, fact); 
    }
    return 0;
}

output


enter a number : 4
factorial of 4 = 24

How to use sum of this series in c language

program to use sum of this series in c language


#include<stdio.h>
int main()
{
    int i,n,sum=0,term=1;
    printf("Enter number of terms : ");
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    { 
        sum+=term;
        term = term+i;
    }
    printf("the sum of series upto %d term is %d\n",n,sum);
    return 0;
}

output


Enter number of terms : 3
the sum of series upto 3 term is 7 

How to use multiply operator in c language

program to use multiply operator in c language


#include<stdio.h>
int main()
{
    int a,b,i;
    int result=0;
    printf("Enter two numbers to be multiplied : ");
    scanf("%d%d",&a,&b);
    for(i=1; i<=b; i++)
    {
        result=result+a;
        printf("%d * %d = %d\n",a,b,result);
    }
    return 0;
}

output


Enter two numbers to be multiplied : 12
3
12 * 3 = 12
12 * 3 = 24
12 * 3 = 36