Wednesday, 17 July 2019

If Statement Programs in C

If Statement Programs in C 




If Statement in C


Hello Friends,

Today we will discuss about C language Statements.

There are two types of Statements in C language.

1.Selection Statements or Decision Statements
2.Iteration Statements or Control Statements


Selection Statements : Selection Statements  executes different sections of code depending on a specific condition or the value of a variable.There are two types of selection statements :

  • If - else
  • Switch-case  
lets see an example :

Here, We are finding greatest number from 2 numbers using if statement..

If statement program in C

If statement demo in c




Here we are finding greatest number among 3 numbers using If Statement with the help of logical operator(AND).

 If Statements is used to compare two operands .It can take multiple condition using logical operators.
 If Statement can be categorized in different ways - If-else, ElseIf,NestedIf,MultipleIfs etc...

Lets take another example

A program to display greatest number among three numbers.

Program using if statement in c

Demo using if statement in c

Lets take some more examples of If Statements

Here we are using else if statement .

A program to display total marks ,average and grade of a student.


Grade program using if statement in c

if statement grade program



Note:
scanf () function is used to accept input from users. For integer values we use '%d' format specifier.
When user input some value it stored into the variable i.e given as '&variable_name' . '&' symbol would be always used with variable name because it stores the address of memory . We call '&' symbol as 'AddressOf' operator in C language that stores the variable memory location.



 we will continue  with if Statements Program.



Lets take an another example of If Statement with  Operators(Logical,Relational).

A program to find average of six subjects and display the results.

Average
Result
>=35 and <50
Third Division
>49 and <60
Second Division
>=60 and <75
First Division
>=75 and <=100
Distinction
<35 or if marks in any subject less than 35
Fail










A program to calculate the gross salary for the conditions given below.

Basic Salary (Rs.)
DA (Rs.)
HRA (Rs.)
Conveyance (Rs.)
>=5000
110% of Basic
20% of Basic
500
bs>=3000 && bs<5000
100% of Basic
15% of Basic
400
bs<3000
90% of Basic
10% of Basic
300






Output:




No comments:

Post a Comment

Recent Post

Python Project | Banking System | Project on Banking System using python

  PYTHON PROJECT Banking System import csv import pandas as pd import matplotlib.pyplot as plt import sys import datetime found=False def ne...