


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concepts of structured programming, control structures, if statement, if-else statement, switch statement, relational operators, and logic operators in c. It includes examples and sample code for grade calculation and quadratic equation root finding.
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



if (expression) {
statement_1;
statement_2;
……
statement_n;
}
If statement with compound statement
If-else statement
If-else with compound statement
Relational Operators
n > if (c>b) if c is great than b
n >= if (c>=b) if c is great than or equal to b
n < if (c<b) if c is less than b
n <= if (c<=b) if c is less than or equal to b
n == if (c==b) if c is equal to b
n != if (c!=b) if c is not equal to b
#include <stdio.h> #include <math.h> /* math libaray is included for sqrt() function */
int main( void ) { float a, b, c, delta, div;
printf( "Enter Value for Coefficient 'a', 'b', 'c' : "); scanf( "%f %f %f", &a, &b, &c);
delta = bb - 4.0 * a c; div = 2.0 * a;
if( a == 0 ) { /* if a is 0, only one single root / printf( "Single root = %g\n", -c/b) ; } else { /if a is not 0, then we have two roots / if (delta >= 0.0) { / if roots are real/ printf( "Roots are real\n"); printf( "Root1 = %g\n ", (-b + sqrt(delta))/div ); printf( "Root2 = %g\n ", (-b - sqrt(delta))/div ); } else { / if roots are complex */ printf( "Roots are complex\n"); printf( "Root1 = (%g) + i(%g)\n", - b/div, sqrt(-delta)/div ); printf( "Root2 = (%g) - i(%g)\n", - b/div, sqrt(-delta)/div ); } } return 0 ; } 14