Week 5-C Lab Program
Week 5-C Lab Program
To determine whether a given number is "Odd" or "Even" and print the message
NUMBER IS EVEN or NUMBER IS ODD
with and without using "else" statement.
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int number;
system("clear");
printf("Enter a Number: "); scanf("%d", &number);
return 0;
}
/*
To determine whether a given number is "Positive", "Negative" or "ZERO" and
print the message "NUMBER IS POSITIVE”, “NUMBER IS NEGATIVE” or “NUMBER IS
ZERO” using nested "if" statement.
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int number;
system("clear");
if(number>=0)
if(number>0)
printf("NUMBER IS POSITIVE\n") ;
else
printf("NUMBER IS ZERO\n");
else
printf("NUMBER IS NEGATIVE\n") ;
return 0;
}
// To compute all the roots of a quadratic equation by accepting the non-zero
coefficients. Print appropriate messages.
/* Design, develop and execute a program to find and output all the roots of a
given quadratic equation,
for non-zero coefficients.*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int a, b, c, disc;
float root1, root2;
system("clear");
NEXT:
printf("Enter the Non-Zero Co-efiicients: ");
scanf("%d %d %d", &a, &b, &c);
if(disc<0)
{
printf("Roots are Imaginery....\n");
}
else if(disc>0)
{
root1 = (-b + sqrt(disc)) / (2*a) ;
root2 = (-b - sqrt(disc)) / (2*a) ;
printf("Roots are Real and Distinct\n");
printf("Root-1 = %.2f\n", root1);
printf("Root-2 = %.2f\n", root2);
}
else
{
root1 = root2 = -b / (2*a) ;
printf("Roots are Real and Equal/Identical\n");
printf("Root-1 = %.2f\n", root1);
printf("Root-2 = %.2f\n", root2);
}
return 0;
}