C Programming Assignment 1
C Programming Assignment 1
C PROGRAM:
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
if (num > 0) {
else {
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
Print Print
Print zero
negative positive
Stop
End
CODE:
OUTPUT:
C PROGRAM:
#include <stdio.h>
#include <math.h>
int main() {
disc = b * b - 4 * a * c;
if (disc < 0) {
else if (disc == 0) {
x1 = -b / (2 * a);
else {
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
X1=[-B+SQRT(DISC)]/(2*A)
X1=B/(2*A)
X2=[-B-SQRT(DISC)]/(2*A)
Stop
Stop
CODE:
OUTPUT: