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...

Artificial Intelligence

Artificial Intelligence (AI) in Engineering Artificial Intelligence (AI) is the science of using a computer (program) to help think of solutions to solve a particular problem. This is especially very useful in the field of Engineering; due to the need of constantly trying to automate every process for improved efficiency. Every engineering field has benefitted from the use of AI, some more than others. Computer Engineering Computer Engineering is the primary field in which AI is used. Many companies are preferring AI programming over traditional programming as it allows their programs to be long lasting and avoids the constant need to update. Personal Assistant applications like Google Now, Siri and cortana heavily rely on the use of AI for predicting user behavior and voice recognition. Other application include video games, Purchase prediction, Smart cars, Fraud detection, Security services etc. Instrumentation Engineering Instrumentation Engineering primar...

C Programming #6 (Loop Control Instruction)

In C Programming if we want to repeat some statements here we make the use of loops. There are three methods by which we can repeat part of program. Using for statement Using a while statement Using a do-while statement The while loop: It will repeat the program until the condition in while loop become false. Example: /*Calculation of simple interest for 3 sets of p, n and r*/ #include<stdio.h> int main() { int p,n,count; float r,si; count=1; while(count<=3) { printf("\nEnter values of p,n and r"); scanf("%d%d%f",&p,&n,&r); si=p*n*r/100; printf("Simple interest = Rs. %\nf",si); count=count+1; } return 0; } Here this program while loop has the condition to repeat the program 3 times. As in while loop at the end count is increased by 1 every time it execute and when it reaches to 3 control comes out of program and the program terminates. Tips and Traps As I mentioned in m...