Decision-making in C, as the name suggests, is a way of performing different sets of actions depending on various circumstances.
Shown below is the general form of a regular decision-making structure found in most of the programming languages −
Here, a particular condition statement is tested by the program, which returns true/false accordingly and executes further instructions.
C has three major decision-making instructions-
note: C programming language assumes any non-zero and non-null values as true, and if it is either zero or null, then it is assumed as a false value.
C uses the if keyword to implement the decision control instruction.
Syntax:
if(condition)
{
//Statement executed if condition is true
}
Expression | is true if |
x==y | x is equal to y |
x !=y | x is not equal to y |
x>y | x is greater than y |
x<y | x is less than y |
x>=y | x is greater than or equal to y |
x<=y | x is less than or equal to y |
#include <stdio.h>
int main() {
int num;
printf("Enter a number:");
scanf("%d",&num);
if(num<10)
{
printf("Number is less than 10");
}
return 0;
}
Input : 3
Output:Number is less than 10
Input :21
Output:
hence, we can see that no Result is displayed when the input is greater than 10.
Note: also read about Format specifiers in C & Escape Sequence in C.
If you like my post please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
You manage an e-commerce website and need to keep track of the last N order…
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by πr². Use the Monte…
Given an integer k and a string s, write a function to determine the length…
There is a staircase with N steps, and you can ascend either 1 step or…
Build an autocomplete system that, given a query string s and a set of possible…