0% found this document useful (0 votes)
189 views

C Lab programs vtu 2022 scheme

some lab programs in c language that are super important might come in exams or your lab internal

Uploaded by

realstdbroz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views

C Lab programs vtu 2022 scheme

some lab programs in c language that are super important might come in exams or your lab internal

Uploaded by

realstdbroz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Develop a program to compute the roots of a quadratic equation by

accepting the coefficients. Print appropriate messages.

#include<stdio.h>

#include<math.h>

#include<stdlib.h>

void main()

float a,b,c, root1, root2, realp, imgp, disc;

printf("\n\n Enter the values for coefficients a,b and c: ");

scanf("%f%f%f",&a,&b,&c);

if(a == 0 || b == 0 || c == 0)

printf("\n Invalid Inputs Try Again");

exit(0);

disc = b*b-4*a*c;

if(disc == 0)

printf("\nThe Roots are Equal");

root1 = root2 = -b / (2.0*a);

printf("\n Root1 = Root2 = %f", root1);

if(disc > 0)
{

printf("\n The Roots are Real and Distinct");

root1 = (-b + sqrt(disc))/(2.0*a);

root2 = (-b - sqrt(disc))/(2.0*a);

printf("\nRoot1 = %f", root1);

printf("\nRoot2 = %f", root2);

if(disc < 0)

printf("\n The Roots are Imaginary");

realp = -b/(2.0*a);

imgp = sqrt(fabs(disc))/(2.0*a);

printf("\nRoot1=%f +i %f",realp,imgp);

printf("\nRoot2 = %f -i %f",realp,imgp);

}
Implement Binary Search on Integers.

#include <stdio.h>

#include<stdlib.h>

void main()

int i, low, high, mid, n, key, a[100];

printf("Enter number of elements:\n");

scanf("%d",&n);

printf("Enter integer numbers in ascending order:\n");

for (i = 0; i< n; i++)

scanf("%d",&a[i]);

printf("Enter value to Search:\n");

scanf("%d", &key);

low = 0;

high = n - 1;

while (low <= high)

mid = (low+high)/2;

if (key == a[mid])

printf("%d found at location %d\n", key, mid+1);

exit(0);

}
if (key > a[mid] )

low = mid + 1;

if (key < a[mid])

high = mid - 1;

printf(" %d is Not found \n", key);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy