0% found this document useful (0 votes)
36 views3 pages

Subject: Data Structures & Algorithms: P.C.C.O.E.PUNE-44

This document provides algorithms for two C programs: 1) Checking if a number is prime and 2) Finding the roots of a quadratic equation. The prime number program uses modulo division to check if a number is completely divisible by all integers from 2 to itself. The quadratic equation program calculates the roots using the quadratic formula and checks if the roots are real, equal, or complex based on the discriminant. Examples are given to demonstrate both algorithms. The document aims to help students understand basic C programming concepts.

Uploaded by

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

Subject: Data Structures & Algorithms: P.C.C.O.E.PUNE-44

This document provides algorithms for two C programs: 1) Checking if a number is prime and 2) Finding the roots of a quadratic equation. The prime number program uses modulo division to check if a number is completely divisible by all integers from 2 to itself. The quadratic equation program calculates the roots using the quadratic formula and checks if the roots are real, equal, or complex based on the discriminant. Examples are given to demonstrate both algorithms. The document aims to help students understand basic C programming concepts.

Uploaded by

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

P.C.C.O.E.PUNE-44.

PIMPRI CHINCHWAD COLLEGE OF ENGINEERING


Sector No.26, Pradhikaran, Nigidi, Pune- 411044

Subject: Data Structures & Algorithms


Experiment No: Beyond Syllabus
Date Of performance:
Date of Submission:
Marks:

Title: Basic C Programs


Class: SE
E&TC
Roll No.:
Signature:

Aim of Experiment:
Write C Program for finding the following:
E1) Checking Prime number
E2) Roots of the Quadratic equation

Objectives:
Able to understand the basic concept of a writing the C programs.

Theory & Algorithm

E1: To check whether the given number is Prime number


(Tip: If given number is 1 then it is not prime else if given number is 2 then it is prime
number else if N is not completely divisible by (N-1) till 2.
In short: If N=5 is to be checked whether it is prime number then it should be completely
divisible by the numbers 4, 3, 2
Input: (number N)
Output: To check whether given number is Prime number Result is true or false
Formula: If Remainder R = N/I =0 then N is not prime

SE E & TC

Dept. of E & TC
(SEM-I, 2014-15)

P.C.C.O.E.PUNE-44.

Algorithm:
Step 1: Start
Step 2: Read number N
Step 3: Check if N is less than equal to 1 then N is not prime number then stop
Step 4: Check if N is equal to 2 then N is prime then stop
Step 5: Set count Index I = 2
Step 6: Divide N by I and check Remainder,
if Remainder R = 0 then N is not prime then stop.
Step 7: Increment count index until I <= N
Step 8: Stop

E2: To find the roots of the quadratic equation.


Let the quadratic equation be: ax+ bx+ c

Roots of quadratic equation are:


x1 = (-b+ (b-4ac))/2a
x2 = (-b-( b-4ac))/2a

The possible cases are:


If -( b-4ac) < 0 then roots are complex conjugates
If -( b-4ac) = 0 then roots are real and equal
If -( b-4ac) > 0 then roots are real and unequal

Algorithm:
Step 1: Start
Step 2: Input the Coefficients of quadratic equation

SE E & TC

Dept. of E & TC
(SEM-I, 2014-15)

P.C.C.O.E.PUNE-44.

Step 3: Calculate - (b-4ac)


Step 4: If - (b-4ac) < 0 then roots are complex conjugates
Step 5: Else If (b-4ac) = 0 then roots are real and equal
Step 6: Else If ( b-4ac) > 0 then roots are real and unequal
Step 7: Stop

Example:
The quadratic equations 2X+ 5X + 3
- (b-4ac) = (25-4*2*3) = 1

hence roots are real and unequal

x1 = (-5 + 1)/ (2*2) = - 1


x2 = (-5 1)/ (2*2) = -3/2

References:
1. C programming by Balguruswami.
2. Let us C Kanetkar.
3. Fundamentals of data structures sartaj sahani.

Conclusion:

SE E & TC

Dept. of E & TC
(SEM-I, 2014-15)

You might also like