Jul 7, 2024
A + B, A and B are operands, and + is the operator.+ (addition)- (subtraction)* (multiplication)/ (division)% (modulus)< (less than)<= (less than or equal to)> (greater than)>= (greater than or equal to)== (equal to)!= (not equal to)&& (logical AND)|| (logical OR)! (logical NOT)& (bitwise AND)| (bitwise OR)^ (bitwise XOR)~ (bitwise NOT)<< (left shift)>> (right shift)=+=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |=++ (increment)-- (decrement)? :,sizeof++A, --BA + B, A - Bcondition ? expr1 : expr2* has higher precedence than +, so in A + B * C, B * C is evaluated first.+ and - with the same precedence, associativity is left-to-right, so in A - B + C, A - B is evaluated first.*int and float in an expression results in the int being converted to float.(type) value(int) 3.14ifif-elseif-else-ifswitchwhiledo-whileforbreakcontinuegoto#include <stdio.h>
int main() {
int a = 5, b = 3;
a = a + b; // a = 8
b = a - b; // b = 5
a = a - b; // a = 3
printf("a = %d, b = %d", a, b);
return 0;
}
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0)
printf("%d is even", num);
else
printf("%d is odd", num);
return 0;
}
ax┬▓ + bx + c = 0D = b┬▓ - 4ac#include <math.h>
#include <stdio.h>
int main() {
double a, b, c, discriminant, root1, root2;
printf("Enter coefficients a, b, and c: ");
scanf("%lf %lf %lf", &a, &b, &c);
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Roots are real and distinct: %.2lf, %.2lf", root1, root2);
} else if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf("Roots are real and equal: %.2lf, %.2lf", root1, root2);
} else {
printf("Roots are imaginary");
}
return 0;
}
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf(" %c", &c);
switch (c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("%c is a vowel", c);
break;
default:
printf("%c is a consonant", c);
}
return 0;
}
switch(expression) { case value1: statements; break; ... default: ; }break statements.if (condition) { statements } else { }break statements.