C if-else Statement :

if-else :

if-else statement is used to execute a statement block or a single statement depending on the value of a condition.

Example 1 :

  1. /* Description: program to find biggest of two numbers */
  2. #include<stdio.h>
  3. #include<conio.h>
  4. main()
  5. {
  6. int a,b,big;
  7. //clrscr();
  8. printf("\n Enter two numbers:\n");
  9. scanf("%d %d",&a,&b);
  10. big=a;
  11. if(b>big)
  12. big=b;
  13. printf("\n Biggest number is %d",big);
  14. getch();
  15. }

Note : clrscr() It is predefined function in "conio.h" (console input output header file), by using this function we can clear the data from consol(Monitor), Here we skip this function( just remove // to you can use this function ).
getch() is a way to get a user inputted character (getch() andgetchar() are used to read a character from screen). It can be used to hold program execution.

Output 1 :

c language - program to find biggest of two numbers

Example 2 :

  1. /* Description: simple if-else example */
  2. #include<stdio.h>
  3. main()
  4. {
  5. int a;
  6. printf("\n Enter only number 1\n");
  7. scanf("%d",&a);
  8. if(a==1)
  9. {
  10. printf("You enter right number.");
  11. }
  12. else
  13. {
  14. printf("You press wrong number.");
  15. }
  16. getch();
  17. }

Output 2 :

c language - simple if-else example

Next Update

Loading...

We have two YouTube channels their name is CodeX or NightHawk. CodeX is for programming related videos and NightHawk is for online game streaming so please supporting us and Subscribe to our channels