SQL PHP HTML ASP JavaScript articles and free scripts to download
 

if else in C program

We can use decision making statement if else inside our c code. For this we will start with some simple if else statement and write complex programs in our c language.

If( test expression )
{
Statement block if TRUE
}

Similarly we can add else part to our if condition so if the test expression fails then this part gets executed. We will start with an example. We will ask users to enter one digit , then we will check if it is greater than 10 or not. But to display a message if the condition checking fails we have to use one else block also. Here is the code.

#include <stdio.h>
int main(void){
int num1;
printf("Enter the number ");
scanf("%d",&num1); // Enter numbers
if(num1 <= 10)
{
printf(" Your number is less than or equal to ten");
}
else
{
printf(" Your number is more than ten"); // printng outputs
}
return 0;
}




Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
Basic of C
C Sections