if statement with two else statements : If statement « Statement « C Tutorial

Home
C Tutorial
1.Language
2.Data Type
3.String
4.printf scanf
5.Operator
6.Statement
7.Array
8.Function
9.Structure
10.Pointer
11.Memory
12.Preprocessor
13.File
14.Data Structure
15.Search Sort
16.Wide Character String
17.assert.h
18.ctype.h
19.math.h
20.setjmp.h
21.signal.h
22.stdio.h
23.stdlib.h
24.string.h
25.time.h
26.wctype.h
C / ANSI-C
C++
C++ Tutorial
Visual C++ .NET
C Tutorial » Statement » If statement 
6.3.6.if statement with two else statements
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    char num[2];
    int number;
 
    printf("Enter a number from 0 to 9:");
    gets(num);
    number=atoi(num);
 
    if(number<5)
    {
        printf("That number is less than 5!\n");
    }
    else if(number==5)
    {
        printf("You typed in 5!\n");
    }
    else
    {
        printf("That number is more than 5!\n");
    }
 
    return(0);
}
Enter a number from 0 to 9:2
      That number is less than 5!
6.3.If statement
6.3.1.if statement
6.3.2.To execute only one statement, opening and closing braces are not required
6.3.3.The if statement: a compound statement
6.3.4.If with else statement
6.3.5.The if-else-if statement
6.3.6.if statement with two else statements
6.3.7.if statement: compare the value from user input
6.3.8.Using nested ifs
6.3.9.Use compound conditions to check for upper and lowercase letters
6.3.10.Checking for a Range of Values
6.3.11.Use isdigit Function in if statement
6.3.12.Operators Used in if Comparisons
6.3.13.if Comparisons and Their Opposites
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.