IF ELSE

Simple IF ELSE Statement



Here is an example for simple if else statement.

if statement evaluates the condition inside the paranthesis and if it is true, then it executes one line followed by if statement or the sequence of steps bound of { }.

if statement can be combined with else part. Else part will be executed when the if condition is false.


Source Code


#include <stdio.h>


void main()
{
   int x;

   printf("Enter a Number: ");
   scanf("%d", &x);

   if(x < 0)
      printf("%d is a negative number\n", x);
   else
      printf("%d is a positive number\n", x);
}

Output


Enter a Number: -100
-100 is a negative number

Enter a Number: 55
55 is a positive number

৪টি মন্তব্য:

  1. #include
    main()
    {
    int y=2;
    printf("enter a number");
    if (y<0)
    printf("%d is a negative number\n",y);
    else
    printf("%d is a positive\n",y);

    }

    উত্তরমুছুন
  2. #include
    main()
    {
    int y=2;
    printf("enter a number");
    if (y<0)
    printf("%d is a negative number\n",y);
    else
    printf("%d is a positive\n",y);

    }

    উত্তরমুছুন
  3. ///simple if else statement///
    #include
    int main()
    {
    int n;
    n=10;
    if(n>=0)
    {
    printf("The number is positive\n");
    }
    else
    {
    printf("The number is negative\n");
    }
    return 0;
    }

    উত্তরমুছুন
  4. ### simple if else statement ###

    #include
    main()
    {
    int a,b;
    scanf( "%d"& a );
    scanf( "%d"& b );

    if(a<b)

    printf( "b is big" );

    else

    printf ( " a is big ");
    }

    উত্তরমুছুন