IF Statement

Simple IF Statement



Here is an example for simple if 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 { }.

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);
}

Output


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

৫টি মন্তব্য:

  1. //write a program to print the largest number
    //from any four numbers.
    #include
    main()
    {
    int a,b,c,d;
    printf("The value of a :");
    scanf("%d",&a);
    printf("\nThe value of b :");
    scanf("%d",&b);
    printf("\nThe value of c :");
    scanf("%d",&c);
    printf("\nThe value of d :");
    scanf("%d",&d);
    if((a>b)&&(a>b)&&(a>c))
    printf("\nThe largest number: %d",a);
    else
    if((b>c)&&(b>d))
    printf("\nThe largest number: %d",b);
    else
    if(c>d)
    printf("\nThe largest number: %d",c);
    else
    printf("\nThe largest number: %d\n",d);
    }

    উত্তরমুছুন
  2. ///simple if statement///
    #include
    main()
    {
    int n;
    printf("Enter a number");
    scanf("%d",&n);
    if(n<1)
    printf("%d is a negative number\n:",n)
    }

    উত্তরমুছুন
  3. ///simple if statement///
    #include
    main()
    {
    int n;
    printf("Enter a number:");
    scanf("%d",&n);
    if(n<1)
    printf("%d is a positive number\n",n);
    return 0;
    }

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

    #include
    main()
    {
    int r;
    printf("enter a number");
    scanf("%d,& r);
    if(r>1)
    printf("%d is a positive number\n",r);
    }

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

    উত্তরমুছুন