Write a program to check weather a number is positive or not positive using IF



Q1 Write a program to check weather a number  is positive or not positive using if

IF ----If  statement is one of the simplest  decision making control statement.


Syntax

If (expression)
{
        Frist   Statement ;
       …… ………… ……… …………..
       …… ………… …………  ………
      Last  statement;
  }


How to work if statement

The if statement evaluates the take a look at expression within the parenthesis ().
If test condition  is evaluated to true, statements within the body of if are executed.
If test condition  is evaluated to false, statements within the body of if don't  executed

If condition  is true
Int check =10;
If (check < 33)
{
  //  executed code
}
// executed code after if

If condition  is false
Int check =10;
If (check >33)
{
  //  executed code
}

// executed code after if

PROGRAM


#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
    int a;
    printf("ENTER A NUMBER");
    scanf("%d",&a);
    if (a>0)
    {
        printf("positive number");
       
    }
    if(a<=0)
    {
        printf("non positive number");
       
    }
     
    return (EXIT_SUCCESS);
}

OUTPUT


 Write a program to check weather a number  is positive or not positive


 Write a program to check weather a number  is positive or not positive



Q 2 WRITE A C PROGRAM  TO CHECK WEATHER RESULT


#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
   
    int a;
    printf("ENTER A RESULT");
    scanf("%d",&a);
    if (a>=33)
    {
        printf("PASS");
       
    }
    if(a<33)
    {
        printf("BUTTER LUCK NEXT TIME");
       
    }
     
    return (EXIT_SUCCESS);
}

OUTPUT




 Write a program to check weather a number  is positive or not positive





Q3 Write a c program to check a voting AGE condition


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv)
{
   
    int a;
    printf("ENTER A AGE");
    scanf("%d",&a);
    if (a>=18)
    {
        printf("YOU CAN VOTE");
       
    }
    if(a<18)
    {
        printf("YOU CAN'T VOTE");
       
    }
     
    return (EXIT_SUCCESS);
}


OUTPUT
 Write a program to check weather a number  is positive or not positive

 Write a program to check weather a number  is positive or not positive










Comments

Popular posts from this blog

Create a structure TIME with members hours, minutes and seconds. Write a C program to add two time objects by passing structure variables to function and display result in H: M: S format.

Create a structure named company which has name, address, phone and no of Employee as member variables. Read name of company, its address, phone and no of Employee. Finally display these members’ value.

Write a c program to check a voting AGE condition using if-else