if control statements in c programming

21 Aug 2022 Balmiki Mandal 0 C Programming

If Statements

if is a conditional Non-iterative control statement, once the condition is true then if control statement  is going to perform otherwise coming to the next condition

 

Program 01:

#include<stdio.h>
int main()
{
    printf("Hii electro4u....");
    if(0)
    printf("hai...\n");
    printf("bye....\n");
}

Attentions : in this program, if we put inside the if the condition  0  so it means conditional fails.  so control goes for searching the else condition but in this program else condition is not there so control goes to another statement. bye......  is not part of if condition only Hii electro4u.... is part of it. so it means bye is another statement so the result is Hii electro4u.....bye......

if else statements

 if else is a conditional Non-iterative control statement. if the condition is True execution happens on the true condition if the condition is false execution is performed on false statements. it basically depends upon true or false statements 

 write a program to find a character in an upper or lower case using if else

#include<stdio.h>
int main()
{
    char ch;
    printf("Enter a Character:");
    scanf("%c",&ch);
    // if(ch>=97&&ch<=122);
    if(ch>='a'&&ch<='z')
    printf("This is lower chacter\n");
    else
    printf("This is upper chacter\n");
}

Attension

This program is based on finding the alphabet type in upper case or lower case. if we give a small latter like a b c so it's a lower case latter if we give A B C D so it's an upper letter.

Nested If of if else ladder: 

Nested if else is a conditional Non-iterative control statement in this control statement inside if another if else condition is present is called a nested if-else control statement.

Some Programs are based on conditions

  • Write A program to scan a character from the user and display that character and its ASCII value only if the given input is small later.
  • Write a program to scan a character from the user and display the given character in lower case and uppercase
  • write the program form student marks.
  • Write a program for student database
  • Write A program to scan a number and bits position from the user after that display a menu for the options 1. set bit 2. clear bit 3. compliment a bit scan and options from the user depending on the options provided by the user perform the task and display the result.

Further Reading:

 For further information and examples, Please visit[ C-Programming From Scratch to Advanced 2023-2024]

 

 

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.