Skip to main content

C Programming #5 (Complex decision making)

Decision making is very important in C program so to get most out of it similar to boolean maths in C we use logical operators
Using if else can be tough while making program with some specific condition

So here you can use operators like:
if((percentage>=50)&&(percentage<60))
printf("Second division");

Here && in if statement is working as AND operator in this both the condition is to be true so that command in if statement to be execute.
So if || is used it is similar to OR operator in this type of statement any one condition is to be true for command to be executed.
and ! is NOT operator we will see this one in detail in my further blogs.
The conditional operator:
The for of conditional operator is like
 expression 1? expression 2 : expression 3
It mean if the expression 1 is true then exp 2 will be executed if not then exp 3 will be executed.
Example:
int x,y;
scanf("%d",&x); /*Here I have used scanf to take input from user*/
y=(x>5?3:4);

This program in if else format will be like 

if(x>5)
y=3;
else
y=4;


Note:You can try new tough condition and compile it so that you get your hands better in C programming and for any kind of question you are most welcome try this and send me your programs in comments.

Comments

Popular posts from this blog

Android O (Android Operating system)

There are many kind of changes and improvements in this new version of Android OS. Increased Ability of the mobile:- aptX bluetooth streaming :-   High quality audio codec is supported for streaming to bluetooth Headsets and Speakers Adaptive icons give devs and OEMs easy shape masks, extra effects :-  "an OEM like Samsung or HTC will provide a unifying mask, which will allow developers to integrate almost any existing app icon into the broader user interface with minimal effort, and no extra graphics work on the icon itself." Neighborhood Aware Networking (NAN) mode for WiFi :-  "You can think about NAN as a combination of WiFi Direct and Nearby. Two hypothetical phones with NAN could find each other and connect without any additional apps or configuration, allowing them to share data at high speeds." Picture-in-picture video for all devices and new windowing features :- "The gist is that when watching video on Android O, you'll be able to shr...

C Programming #8 (Case Control Instruction)

In Programming we come across some situations where we have to choose from number of alternatives and choice should be specific to condition so the control statement that allow us to make a decision from number of choice is called as switch or we can say switch-case as they are used together. The switch statement looks like : switch (integer expression) { case constant 1: do this; case constant 2: do this; case constant 3: do this; default: do this; } In these case do this is the command statement that is to be followed when case is satisfied Example: #include<stdio.h> int main() { int i=2; switch(i) { case 1: printf("I am in case 1\n"); case 2: printf("I am in case 2\n"); case 3: printf("I am in case 3\n"); default: printf("I am in default"); } return 0; } Output of the program will be : I am in case 2 I am in case 3 I am in default But this is not the output we needed this program should give us...