Java Script Language

Basic Programming

WAP to input a number and print double.

	int main()
	{
	int a;
	printf("Enter a number ");
	scanf("%d",&a);
	printf("Double of number is %d",a*2);
	}			
	

WAP to input a number and print half of number.

	int main()
	{
	int a;
	printf("Enter a number ");
	scanf("%d",&a);
	printf("Double of number is %d",a*2);
	}			
	

WAP to input a number and print half of number.

	int main()
	{
	int a;
	printf("Enter a number ");
	scanf("%d",&a);
	printf("Double of number is %d",a*2);
	}			
	

if - else

1. WAP to input a number and check if the number is positive and negative.


    int main()
    {
        int n;
        printf("Enter a number");
        scanf("%d",&n);
        if(n>0)
            printf("Positive Number");
        else
            printf("Negative Number");
        getch();
    }
        

2. WAP to input two numbers and print the largest number between the numbers.


    int main()
    {
        int x,y;
        printf("Enter a first number");
        scanf("%d",&x);
        printf("Enter a second number");
        scanf("%d",&y);
        if(x>y)
        printf("First number is  Largest Number");
        else
        printf("Second number is Largest Number");
        getch();
    }
        

3. Wap to input two numbers and print the square of the smallest number between the numbers.


    int main()
    {
        int x,y;
        printf("Enter a first number");
        scanf("%d",&x);
        printf("Enter a second number");
        scanf("%d",&y);
        if(x < y)
        printf("First number %d\n",x*x);
        else
        printf("Second number %d\n",y*y);
        getch();
    }

        

4. WAP to input your age and check if the user can vote or not.


    int main()
    {
        int age;
        printf("Enter an age of person  ");
        scanf("%d",&age);
        if(age>=18)
        printf("Permission granted to give vote");
        else
        printf("Permission not granted to give vote");
        getch();
    }
        

5. WAP to input the monthly salary and calculate the yearly salary if yearly salary is greater than 2 lakh calculate 10% income tax otherwise 8% income tax.


    int main()
    {
        float ms,ys,tax;  // ms- monthly salary , ys-yearly salary
        printf("Enter a monthly salary");
        scanf("%f",&ms);
        ys=ms*12;
        printf("\n Yearly Salary");
        if(ys>200000)
        tax=ys*.10;
        else
        tax=ys*.08;
        printf("\n%f",tax+ys);
        getch();
    }
        

6. WAP to input the mars of 5 subjects and calculate the total marks and percentage if the percentage is greater than 60% print pass otherwse fail.


    int main()
    {
        float h,e,m,p,c,marks,per;  // h-hindi,e-english,m-math,,p-physics,c-chemistry
        printf("Enter a Hindi marks");
        scanf("%f",&h);
        printf("Enter a English marks");
        scanf("%f",&e);
        printf("Enter a Maths marks");
        scanf("%f",&m);
        printf("Enter a Physics marks");
        scanf("%f",&p);
        printf("Enter a Chemistry marks");
        scanf("%f",&c);
        marks=(h+e+m+p+c);    // total marks
        printf("Total marks %f\n",marks);
        per=marks/5;        // percentage 
        printf("Percentage %f\n",per);
        printf("\n percentage ");
        if(per>=60)
        printf("Pass");
        else
        printf("Fail");
        getch();
    }

        

7. WAP to input a number and check it is even or odd numbers.


    int main()
    {
        int x;      // where x is a any number
        printf("Enter a number");
        scanf("%d",&x);
        if(x%2==0)
        printf("Even Number");
        else
        printf("Odd Number");
        getch();
    }

        

8. WAP to input a year and check it is Leap year or not.

    int main()
    {
        int x;      // where x is a year
        printf("Enter a year");
        scanf("%d",&x);
        if(x%4==0 && x%100==0 && x%400==0)
        printf("Leap Year");
        else
        printf("It is not Leap Year");
        getch();
    }
        

9. WAP to input your age and check if the user is a senior citizen or not.


    int main()
    {
        int age;
        printf("Enter an age of person  ");
        scanf("%d",&age);
        if(age>=60)
        printf("Senior Citizen");
        else
        printf("Not a Senior Citizen");
        getch();
    }
        

10. WAP to input number and check it is Buzz Number.

            
    int main()
    {
        int x;      // where x is a any number
        printf("Enter a number");
        scanf("%d",&x);
        if(x%7==0 || x%10==7)
        printf("Buzz Number");
        else
        printf("Not a Buzz Number");
        getch();
    } 
        

11. WAP to input a Character and check it is Vower Consonant.

            
    int main()
    {
        char x;      // where x is a any character
        printf("Enter a character");
        scanf("%c",&x);
        if(x=='A'|| x=='E' || x=='I' || x=='O' || x=='U' || x=='a'|| x=='e' || x=='i' || x=='o' || x=='u')
        printf("Vowel");
        else
        printf("Consonant");
        getch();
    }
        

12. WAP to input sales if sales is greater than 2lakh calculate 5% tax otherwise no tax& also print tax and total sales.

    #include<stdio.h>
    int main()
    {
        float x,tax;      // where x is a sales
        printf("Enter a sales");
        scanf("%f",&x);
        if(x>200000)
        {
        tax=(.05*x);
        printf("tax is %f\n",tax);
        }
        else
        printf("NO TAX");
        printf("\n total sales %f",x+tax);
        getch();
    }
        

if - else ladder

Nested if - else

For Loop

while loop

do while loop

Array 1D