Example : Write a program in c to check whether voter is eligible for 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");
   		else
			printf("You are not eligible for voting in election");
	getch();
}

Example : Write a program in c to check & print which accepted value is larger .

#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 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 whether the given no. is +ive, -ive or zero .

#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 calculate root values of 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();
}

 954 total views,  1 views today

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.