C 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

WAP to print your name 5 times

	void main()
	{
	int i;
	for(i=1;i<=10;i=i+1)
	{
	printf("\nTCE Education");
	}
	}
	

WAP to print 1 to N number counting

	void main()
	{
	int i,no;
	printf("Enter the n number");
	scanf("%d",&no);
	for(i=1;i<=no;i=i+1)
	{
	printf("\n%d",i);
	}
	}
	

WAP to print the sum of 1 to 10

	void main()
	{
	int a,sum=0;
	for (a=1;a<=10;a=a+1)
	{
	    sum=sum+a;
	}
	printf("%d",sum);
	}
	

WAP to print the table of 5

	void main()
	{
	int a;
	for (a=5;a<=50;a=a+5)
	{
	printf("\n%d",a);
	}
	}
	

Range Programe

1,2,3,4.............20
	void main()
	{
	int i;
	for(i=1;i<=20;i=i+1)
	{
	printf("\n%d",i);
	}
	}
	

2,4,6,8.............20
	void main()
	{
	int i;
	for(i=2;i<=20;i=i+2)
	{
	printf("\n%d",i);
	}
	}
	

2,4,6,8.............1024
	void main()
	{
	int i;
	for(i=2;i<=1024;i=i*2)
	{
	printf("\n%d",i);
	}
	}
	

5,11,17,23.............65
	void main()
	{
	int i;
	for(i=5;i<=65;i=i+6)
	{
	printf("\n%d",i);
	}
	}
	

0.5,1,1.5.............5
	void main()
	{
	float i;
	for(i=0.5;i<=5;i=i+0.5)
	{
	printf("\n%f",i);
	}
	}
	

1,4,9.............81
	void main()
	{
	int i;
	for(i=1;i<=9;i=i+1)
	{
	printf("\n%d",i*i);
	}
	}
	

1,11,111,1111,11111
	void main()
	{
	int i;
	for(i=1;i<=11111;i=i*10+1)
	{
	printf("\n%d",i);
	}
	}
	

0,7,26,63.......p terms
	void main()
	{
	int i,p;
	printf("Enter the n number of series");
	scanf("%d",&p);
	for(i=1;i<=p;i=i+1)
	{
	printf("\n%d",i*i*i-1);
	}
	}
	

0,3,8,15,24................to n terms
	void main()
	{
	int i,n;
	printf("Enter the n number of series");
	scanf("%d",&n);
	for(i=1;i<=n;i=i+1)
	{
	printf("\n%d",i*i-1);
	}
	}
	

9,1,8,2,7,3,6,4,5,5
	void main()
	{
	int i,a,b;
	a=9;
	b=1;
	for(i=1;i<=5;i=i+1)
	{
	printf("\n%d",a);
	printf("\n%d",b);
	a=a-1;
	b=b+1;                        
	}
	}
	

-9,-1,8,-7,-3,6,-5,-5,4
	void main()
	{
	int i,a,b,c;
	a=-9;
	b=-1;
	c=8;
	for(i=1;i<=5;i=i+1)
	{
	printf("\n%d",a);
	printf("\n%d",b);
	printf("\n%d",c);
	a=a+2;
	b=b+(-2);
	c=c-2;
	}
	}
	

WAP to input a number and print it's table

	void main()
	{
	int no,i;
	printf("Enter a number");
	scanf("%d",&no);
	for(i=no;i<=no*10;i=i+no)
	{
	printf("\n%d",i);
	}

	}
	

WAP to print the factorial of the Given Number

	void main()
	{
	int i,no,fact=1;
	printf("Enter a number");
	scanf("%d",&no);
	for (i=1;i<=no;i=i+1)
	{
	fact=fact*i;
	}
	printf("Factorial of the number is %d",fact);
	}
	

WAP to check given number is PRIME Number or not

	void main()
	{
	int i,no,count=0;
	printf("Enter a number");
	scanf("%d",&no);
	for (i=1;i<=no;i=i+1)
	{
	if (no%i==0)
	{
		count++;
	}
	}
	if (count==2)
	{
	printf("Number is prime");
	}
	else
	{
	 printf("Number is not prime");
	}
	}
	

WAP to check given number is PERFECT Number or not

	void main()
	{
	int i,no,sum=0;
	printf("Enter a number");
	scanf("%d",&no);
	for(i=no;i>1;i=i-1)
	{
	if (no%i==0)
	{
	sum=sum+i;
	}
	}
	if (sum==no)
	{
	printf("Number is perfect number");
	}
	else
	{
	printf("Number is not perfect number");
	}
	}
	

WAP to print the sum of odd number from 1 to 10

	void main()
	{
	int i,sum=0;
	for (i=1;i<=10;i++)
	{
	if (i%2==1)
	{
	sum=sum+i;
	}
	}
	printf("Sum of the odd number %d",sum);
	}
	

while loop

do while loop

Array 1D