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

C Programming Assignment 1

The document contains C code, algorithms, and flowcharts to determine if a number is positive, negative, or zero, and to calculate the roots of a quadratic equation. For the first problem, the code prompts the user for a number, uses if/else statements to check its sign, and prints the result. The algorithm and flowchart show the steps. For the second problem, the code inputs coefficients, calculates the discriminant, and uses if/else statements to determine the type and values of the roots. The algorithm and flowchart similarly outline the steps to solve the quadratic formula.

Uploaded by

sambit.222103101
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

C Programming Assignment 1

The document contains C code, algorithms, and flowcharts to determine if a number is positive, negative, or zero, and to calculate the roots of a quadratic equation. For the first problem, the code prompts the user for a number, uses if/else statements to check its sign, and prints the result. The algorithm and flowchart show the steps. For the second problem, the code inputs coefficients, calculates the discriminant, and uses if/else statements to determine the type and values of the roots. The algorithm and flowchart similarly outline the steps to solve the quadratic formula.

Uploaded by

sambit.222103101
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

C PROGRAMMING ASSIGNMENT #1

Q1) WRITE A PROGRAM, ALGORITHM AND DRAW FLOWCHART TO FIND ENTERED


NUMBER IS POSITIVE, NEGATIVE OR ZERO.

C PROGRAM:

#include <stdio.h>

int main() {

int num;

printf("Enter a number: ");

scanf("%d", &num);

if (num > 0) {

printf("%d is a positive number.\n", num);

else if (num < 0) {

printf("%d is a negative number.\n", num);

else {

printf("The number is zero.\n");

return 0;

ALGORITHM:

1. Start
2. Declare an integer variable num.
3. Prompt the user to enter a number.
4. Read the number entered by the user.
5. Check if the number is greater than 0.
6. If the number is greater than 0, print "The number is positive".
7. If the number is less than 0, print "The number is negative".
8. If the number is equal to 0, print "The number is zero".
9. Stop
FLOWCHART:

Start

Declare Variable

Input
num

Check if

num == 0 num < 0 num > 0

Print Print
Print zero
negative positive

Stop
End
CODE:

OUTPUT:

Q3) WRITE A PROGRAM, ALGORITHM AND DRAW FLOWCHART TO CALCULATE ROOTS


OF QUADRATIC EQUATIONS.

C PROGRAM:

#include <stdio.h>

#include <math.h>
int main() {

float a, b, c, disc, x1, x2;

printf("Enter coefficients a, b and c: ");

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

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

if (disc < 0) {

printf("Roots are Complex.\n");

else if (disc == 0) {

x1 = -b / (2 * a);

printf("Roots are Real and Repeated.\n");

printf("Roots are %.2f and %.2f\n", x1, x1);

else {

x1 = (-b + sqrt(disc)) / (2 * a);

x2 = (-b - sqrt(disc)) / (2 * a);

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

printf("Roots are %.2f and %.2f\n", x1, x2);

return 0;

ALGORITHM:

1. Start
2. Input A,B,C
3. DISC= B2 – 4 A * C
4. IF (DISC < 0) THEN
Write Roots are Complex
Stop
ENDIF
5. IF (DISC==0) THEN
Write Roots are Real and Repeated
X1 = - B/(2*A)
Write Roots are X1,X1
Stop
ENDIF
6. IF (DISC >0)
Write Roots are Real and Distinct
X1= (- B + SQRT(DISC)) / (2*A)
X2= (- B + SQRT(DISC)) / (2*A)
Write Roots are X1,X2
7. Stop

FLOWCHART:

Start

Declare Variables

Input A, B, C

DISC = B2 - 4A * C

?
DISC

Write Roots are Write Roots are Write Roots are


Real & Distinct Complex Real & Repeated

X1=[-B+SQRT(DISC)]/(2*A)
X1=B/(2*A)
X2=[-B-SQRT(DISC)]/(2*A)

Roots are Roots are


X1 & X2 X1, X1

Stop
Stop
CODE:

OUTPUT:

You might also like