DO NOT MISS

Ads

Saturday 16 July 2016

C-Programs Using Conditional Operators



* write a program to check whether the given number is even (or) odd.

#include<stdio.h>
#include<conio.h>

void main()

         {

             
int n;
              clrscr();

              printf("enter a number:");
              scanf("%d",&n);

              n%2==0?printf("even"):printf("odd");

              getch();

         }

Output:-



enter a number:24
even
enter a number:5
odd

* write a program to check whether the given number is +ve (or) -ve.

#include<stdio.h>
#include<conio.h>

void main()

       {

                int n;
                clrscr();

               
printf("enter a number:");
                scanf("%d",&n);

                n>0?printf("positive"):printf("negative");

                getch();

       }
Output:-

enter a number:6
positive
enter a number:-9
negative

* write a program to check whether the given year is Leap year (or) not.

#include<stdio.h>
#include<conio.h>

void main()

    {

           
int a;
           clrscr();

           printf("enter a year:");
           scanf("%d",&a);

         
 a%4==0?printf("leap year"):printf("not leap year");

           getch();

    }
Output:-

enter a year:2014
not leap year
enter a year:2016
leap year

* write a program to Biggest number among the two numbers.

#include<stdio.h>
#include<conio.h>

void main()

     {

           
 int a,b;
             clrscr();

             printf("enter a value:");
             scanf("%d",&a);


             printf("enter b value:");
             scanf("%d",&b);

            a>b?printf("a is big"):b>a?printf("b is big"):printf("a,b are equal");

             getch();

     }
Output:-

enter a value:12
enter b value:8
a is big
enter a value:9
enter b value:
21
b is big
enter a value:15
enter b value:
15
a,b values are equal



* write a program to check whether a person eligible Vote (or) not vote.

#include<stdio.h>
#include<conio.h>

void main()

     {

           int a;
           clrscr();

           
printf("enter a person age:");
           scanf("%d",&a);

           a>18?printf("vote"):printf("not vote");

           getch();

     }
Output:-

enter a person age:43
vote

enter a person age:14
non vote

* write a program to print the a,b values.

#include<stdio.h>
#include<conio.h>

void main()

       {

             
int a,b;
             clrscr();

             b=23;
             a=23>56?b--:b++;

             
printf(“a value=%d\n”,a);
             printf(“b value=%d”,b);
 
             getch();

       }
Output:-

a value =23
b value =
24
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________

Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims