Example : Write a program in c to check whether the voter is eligible to vote or not.
#include<stdio.h>
#include<conio.h>
void main()
{
	int age;
   	printf("Enter your age:");
   	
   	scanf("%d",&age);
   	if(age>=18)
	   printf("You are eligible for voting in election");
   	if(age<18)
	   printf("You are not eligible for voting in election");
	getch();
}

-----------------------------  OR  -------------------------------

#include<stdio.h>
#include<conio.h>
void main()
{
	int age;
   	printf("Enter your age:");
   	
   	scanf("%d",&age);
   	if(age>=18)
   	{
	   printf("You are eligible for voting in election");  
	}
			
   	if(age<18)
   	{
   	   printf("You are not eligible for voting in election");
	}
			
	getch();
}

-----------------------------  OR  -------------------------------

#include<stdio.h>
#include<conio.h>
void main()
{
	int age;
   	printf("Enter your age:");
   	
   	scanf("%d",&age);
   	if(age>=18)
	   printf("You are eligible for voting in election");
   	else
	   printf("You are not eligible for voting in election");
	getch();
}
Example : Write a program in C to print when the condition is true(1) or false(0).
#include <stdio.h>

int main() 
{
    if(1)
    	printf("Hello World");
    else 
    	printf("Hello India");
    return 0;
}

Output:
Hello World

-----------  OR  -----------

#include <stdio.h>

int main() 
{
    if(100)    // if(15)  or if('a')  or if("abc")
    	printf("Hello World");
    else 
    	printf("Hello India");
    return 0;
}

Output:
Hello World

-----------  OR  -----------

#include <stdio.h>

int main() 
{
    if(0)
    	printf("Hello World");
    else 
    	printf("Hello India");
    return 0;
}

Output:
Hello India

-----------  OR  -----------

#include <stdio.h>

int main() 
{
    if(!1)
    	printf("Hello World");
    else 
    	printf("Hello India");
    return 0;
}

Output:
Hello India

-----------  OR  -----------

#include <stdio.h>

int main() 
{
    if(!100)
    	printf("Hello World");
    else 
    	printf("Hello India");
    return 0;
}
Output:
Hello India
Example : Write a program in C to check & print whether the accepted value is positive/negative/zero.
#include <stdio.h> 
#include <conio.h> 
void main () 
{ 
    int a,b;
    clrscr();
    
    printf("Enter a value :");
    scanf("%d",&a);    
    
    if (a>0)
      printf("The value is positive");
    if (a<0)
      printf("The value is negative");
    if (a==0)
      printf("Both values ara equal");
    getch ();
}

-----------------------------  OR  -------------------------------

#include<stdio.h> 
#include<conio.h> 
void main()
{
    int n;
    clrscr();
    printf("Enter Single Value :");
    scanf("%d",&n);
    
    if(n<0)
      printf("The given no. is Negative"); 
    else if (n>0) 
      printf("The given no. is Positive"); 
    else 
      printf("The given no. is Zero"); 
    getch();
}
Example : Write a program in c to check & print which accepted value is larger than two.
#include <stdio.h> 
#include <conio.h> 
void main () 
{ 
    int a,b;
    clrscr();
    
    printf("Enter first value :");
    scanf("%d",&a);
    printf("Enter second value :");
    scanf("%d",&b);
    
    if (a>b)
      printf("First value %d is Larger");
    if (b>a)
      printf("Second value %d is Larger");
    if (a==b)
      printf("Both values ara equal");
    getch ();
}

/*----------------------------  OR  ---------------------------*/

#include <stdio.h> 
#include <conio.h> 
void main () 
{ 
    int a,b;
    clrscr();
    
    printf("Enter first value :");
    scanf("%d",&a);

    printf("Enter second value :");
    scanf("%d",&b);
    
    if (a>b)
      printf("First value %d is Larger");
    else if (b>a)
      printf("Second value %d is Larger");
    else
      printf("Both values ara equal");
    getch ();
}
Example : Write a program in c to check & print the largest value from accepted 3 values.
#include <stdio.h> 
#include <conio.h> 
void main () 
{ 
    int a,b,c;
    //clrscr();
    printf("Enter first value :");
    scanf("%d",&a);
    printf("Enter second value :");
    scanf("%d",&b);
    printf("Enter third value :");
    scanf("%d",&c);    
    
    if ((a>b) && (a>c))
      printf("\nFirst value %d is  the largest",a);
    else if ((b>c) && (b>a))
      printf("\nSecond value %d is the largest",b);    
    else
      printf("\nThird value %d is the largest",c);	
    getch ();
}

------------------------------  OR  -----------------------------

#include <stdio.h> 
#include <conio.h> 
void main () 
{ 
    int a,b,c;
    //clrscr();
    printf("Enter first value :");
    scanf("%d",&a);
    printf("Enter second value :");
    scanf("%d",&b);
    printf("Enter third value:");
    scanf("%d",&c);    
    
    if (a>b)
       {
    	        if(a>c)
		{	
			printf("\nFirst value %d is  the largest",a);		
		}
		else
		{
			printf("\nSecond value %d is the largest",b);		
		}
	}	 
    else		
	{
		if(b>c)
		{
			printf("\nSecond value %d is the largest",b);		
		}
		else
		{
			printf("\nThird value %d is the largest",c);		
		}
	}    	
    getch ();
}
Example : Write a program in c to check & print the most significant/largest value from accepted multiple values.
#include <stdio.h> 
#include <conio.h> 
void main () 
{ 
    int a,b,c,d;
    //clrscr();
    printf("Enter first value :");
    scanf("%d",&a);
    printf("Enter second value :");
    scanf("%d",&b);
    printf("Enter third value :");
    scanf("%d",&c);
    printf("Enter fourth value :");
    scanf("%d",&d);
    
    if ((a > b) && (a>c) && (a>d))
      printf("First value %d is  the largest",a);
    else if ((b>c) && (b>a) && (b>d))
      printf("second value %d is the largest",b);
    else if ((c>a) && (c>b) && (c>d))
      printf("third value %d is the largest",c);
    else
      printf("Fourth value %d is the largest",d);	
    getch ();
}
Example : Write a program in c to check & print whether the given no. is odd or even.
#include<stdio.h> 
#include<conio.h> 
void main()
{
    int n;
    clrscr();
    printf("Enter Single Value :");
    scanf("%d",&n);
    if(n%2==0)
      printf("The given value %d is Even",n); 
    else 
      printf("The given value %d is Odd",n);    
    getch();
} 
Example : Write a program in c to check & print that the given no. is divisible by three, seven, and thirteen.
#include<stdio.h> 
#include<conio.h> 
void main()
{
    int n;
    //clrscr();
    printf("Enter Single Value :");
    scanf("%d",&n);
    
    if(n%3==0 && n%7==0 && n%13==0)
      printf("The given no. is Divisible"); 
    else 
      printf("The given no. is not divisible");    
    getch();
} 
Example : Write a program in c to check & print that the given no. is either divisible by three, seven, or thirteen.
#include<stdio.h> 
#include<conio.h> 
void main()
{
    int n;
    //clrscr();
    printf("Enter Single Value :");
    scanf("%d",&n);
    
    if(n%3==0 || n%7==0 || n%13==0)
      printf("The given no. is divisible by %d",n); 
    else 
      printf("The given no. is not divisible by 3, 7 and 13");    
    getch();
} 
Example : Write a program in C to check whether the given value of Year is Leap Year or Not.
#include <stdio.h>
#include <conio.h>

int main() 
{
   int year;
   
   printf("Enter Year :\n");
   scanf("%d",&year);
   
   if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))
      printf("The given year %d is a Leap year", year);
   else
      printf("The given year %d is not a Leap year", year);

   return 0;
}

---------------------------  OR  --------------------------

#include <stdio.h>
#include <conio.h>

int main() 
{
   int year;
   
   printf("Enter Year :\n");
   scanf("%d",&year);
   
   if (year % 400 == 0) 
   {
      printf("The given Year %d is a Leap Year.", year);
   }
   
   else if (year % 100 == 0) 
   {
      printf("The given Year %d is Not a Leap Year.", year);
   }
   
   else if (year % 4 == 0) 
   {
      printf("The given Year %d is a Leap Year.", year);
   }
   
   else 
   {
      printf("The given Year %d is not a Leap Year.", year);
   }
     return 0;
}
Example : Write a program in c to calculate the root values of a quadratic equation.
#include <stdio.h> 
#include <conio.h>
#include<math.h> 

void main () 
{ 
    float a,b,c,delta,alpha,beta;
	 
    clrscr(); 
    printf("Enter 3 values for the co-efficients :"); 
    scanf("%f%f%f",&a,&b,&c);
    
    delta=(b*b)-(4*a*c);
    printf("Delta=%f ",delta);
    
    if(delta<0) 
    { 
        printf("\nRoots are imaginary\n"); 
    } 
    else if(delta>0)
    {
        alpha=(-b+sqrt(delta))/(2*a);
        beta=(-b-sqrt(delta))/(2*a); 
        printf("The roots are distinct\n"); 
        printf("Alpha=%f\n Beta=%f\n",alpha,beta); 
    } 
    else 
    { 
        alpha=beta=-b/(2*a);
		 
        printf("The roots are equal\n"); 
        printf("Alpha=%f\n Beta=%f\n",alpha,beta); 
    } 
    getch(); 
}

NB: The Standard form of a Quadratic Equation is:ax^2 + bx + c = 0. 
    Here a, b and c are known values and a can't be 0.
    Here"x" is the unknown variable.

    Quadratic Formula: x =  −b ± √(b^2 − 4ac)/2a.
    When the Discriminant (b2−4ac) is:
    positive, there are 2 real solutions.
    zero, there is one real solution
    negative, there are 2 complex solutions
Example : Write a program in c to find out the total factors of an accepted value.
#include <stdio.h>
#include <conio.h>
void main()
{
    int num, i;
    printf("Enter a positive integer value: ");
    scanf("%d",&num);

    printf("Total Factors of %d are: ",num);
    for(i=1;i<=num;i++)
    {
        if(num%i==0)
        {
            printf("%d ",i);
        }
    }
    getch();
}

Loading

Categories: C

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.