Featured Post

80186 Microprocessors: Introduction and Architecture

Hello friends, today we are going to discuss the 80186 microprocessor with integrated peripherals. The Intel 80186 is an improved version of the 8086 microprocessor. 80186 is a 16-bit microprocessor with a 16-bit data bus and a 20-bit address bus. It has a programmable peripheral device integrated into the same package. The instruction set of the 80186 is a superset of the instruction set of the 8086. The term super-set means that all of the 8086 instructions will execute properly on an 80186, but the 80186 has a few additional instructions. The following figure shows the block diagram and pin diagram of 80186. The CPU is divided into seven independent functional parts. 80186 internal block diagram  80186 68-pins pin diagram  Functional parts of 80186 Microprocessor The Bus Interface Unit (BIU) Execution Unit (EU) Clock Generator Programmable interrupt controller Programmable Chip Select Unit (CSU) Programmable DMA Unit Programmable counter/timers The Bus Interface Unit

Nested if Statement in C Programming

Hello friends, in this tutorial we will discuss the if ...else and Nested if statement. In a previous post, I have already discussed the simple if statement used to test a condition, if it is true then the code inside the if statement is executed otherwise the code is not executed. 

if...else statement

The if...else statement having the ability to make a decision among alternative paths means we can execute one group of statements if the condition is true and another group of statements if the condition is false.

Syntax

1. if (logical condition)
program statement 1; // if the condition is true 
else
program statement 2; // if the condition is false


2. if (logical condition)
 group of statements; //if the condition is true }
 else
group of statements; // if the condition is false }

Examples

1. //program to determine whether the person is eligible for driving or not 
int age =25 ;
if (age > 18)
printf("\n The person is eligible for driving"); //true
else
printf("\n The person is not eligible for driving"); //false
In this example, age = 25 so the condition is true and that's why we will get the result " The person is eligible for driving".

2. // program to determine if you entered 5 or any other number.
int i;
printf ("Enter any number");
scanf ( "%d", &i);
if (i==5)
printf("You entered 5");
else
printf(You entered something other than 5")'

In this case, if i =5 then only you will get the result " You entered 5" and if i = 45 then you will get the result "You entered something other than 5".

3. //Program to determine if a number is either even or odd
main ()
{
int number, remainder;
printf ("Enter your number to be tested:");
scanf("%d", &number);
remainder = number %2;
if (remainder ==0)
printf(" The number is even. \n");
else
printf("The number is odd. \n");
}

output 1 
Enter your number to be tested: 56
the number is even 

output 2
Enter your number to be tested: 59
the number is odd

Here in the above example, we have to determine whether the given no is either even or odd by using the mod (%) function. the mod function stores the remainder value.

Nested if statement

The if..else statement constructs within either the body of the if statement or the body of the else statement. this means if the condition in the first if statement is false, then the condition in the second if statement is checked. if it is false as well the final statement is executed.

Syntax

if (condition)
//code   or group of statements
else if (condition)
//code or group of statements
else if  (condition)
// code or group of statements
else
//code or group of statements

Example

1. Program to evaluate simple arithmetic expressions of the form number operator number form 

main()
{
float number1, number2;
char operator;
printf("Give arithmetic values for arithmetic expressions like "23 + 34" \n)'
scanf("%f %c%f", &number1, &operator, &number2);
if (operator == '+')
printf("%f", number1 + number2);
else if (operator == '-')
printf("%f", number1 - number2);
else if (operator == '*')
printf("%f", number1 * number2);
else (operator == '/')
printf("%f", number1 / number2);
}

Output
Give arithmetic values for arithmetic expressions like "23 + 34" 
123 + 59
182

Output (Re-run)
Give arithmetic values for arithmetic expressions like "23 + 34" 
198.7 /26
7.64

Output (Re-run)
Give arithmetic values for arithmetic expressions like "23 + 34" 
89.3 *2.5
223.25

Here we are getting different arithmetic functions to result according to their input values.

If you found this post please let me know as a comment. For video tutors please see my video https://www.youtube.com/watch?v=lG6eUe9WR0g or Subscribed to the My Computer Tutors for updates. I will keep updating to you with latest tutorials.




Comments