TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

C Tutorials

C if-else Statement

Overview

In this tutorial, we will learn about C if-else Statement with examples. The simple if statement only executes the if block when the conditional expression evaluates to true.

C if-else Statement

The general syntax for the C if-else statement is as follows:

if ( condition )
{
     // if block
    // executed when the condition is true
}
else
{
    // else block
   // executed when the condition is false
}

Example

Let’s write a simple C program to illustrate the if-else statements.

/**
**********************************
* Program Description:
* C if-else Statement Demo
* Filename : ifelseDemo.c
* Author : TestingDocs
* Date : 02/02/2017
* C Tutorials - www.TestingDocs.com
*************************************
*/
#include<stdio.h>

int main()
{
 int number = 0;
 printf("Enter the number =");
 scanf("%d",&number);
 // C if-else statement
 if(number % 2 == 0)
 {
 printf("The given number (%d) is Even.\n",number);
 }
 else
 {
 printf("The given number (%d) is Odd.\n",number);
 }

 return 0;
} // end main

C if-else Statement

Related Posts

C Language Characteristics

C Tutorials /

C Language Characteristics

C Source Code .c File

C Tutorials /

C Program Files & Formats

GNU Compiler Collection GCC

C Tutorials /

C Compilers

C Pointers

C Tutorials /

C Pointers

C Tutorials /

C Two-Dimensional Arrays

‹ C Logical Operators› C while Loop

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version