DO NOT MISS

Ads

Wednesday 20 July 2016

Simple-if Statement With C-Programs


The general form of a simple-if statement is

Syntax:-

if(condition)
{
----------
----------
}

( or )

if(condition)
Statement;


In this statement we can check only one condition.It executes only true statement.

First it checks the condition. 

If the condition is true it executes true statement and then goes to next statement. 

If the condition is false it is directly goes to next statement.



Flow chart:-



* write a program to print your name if n value is >10

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

void main()

       {

             
int n;
             clrscr();

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

             if(n>10)
             printf(“AMBATI DURGA PRASAD");

             getch();

        }



Output:-


enter a value: 14
AMBATI DURGA PRASAD



* Write a program to input number is lowest no of 20.



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

void main()

       {

             
int a=10;
             clrscr();

             If(a<=20)
             printf(“a is less than 20”);

             getch();

       }
Output:-

a is less than 20

* Write a program to print the given number is lowest no of 20.

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

void main()

     {

       
 int a;
         clrscr();


         printf(“enter the a value:”);
         scanf(“%d”,&a);

       
 If(a<=20)

         printf(“a is less than 20”);

         getch();

     }
Output:-

enter the a value:19
a is less than 20

* Write a program input your age & print the eligible for vote.

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

void main()

     {

         
int age;
         clrscr();

         printf(“enter your age:”);
         scanf(“%d”,&age);

         If(age>18)

         printf(“you are eligible for vote”);
         printf(“\n Thank you”);

         getch();

    }

Output:-

enter your age: 23 
you are eligible for vote
Thank you


* Write a program input your age & print the u r teenager.

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

void main()

      {

           
int age;
           clrscr();

           printf(“enter your age:”);
           scanf(“%d”,&age);

           If(age>=13&&age<=19)

           printf(“you are teenager”);
           printf(“\n Thank you”);

           getch();

      }
Output:-

enter your age:15
you are teenager
Thank you


* Write a program input two numbers & print the largest value.

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

void main()

    {

       
int a,b,big;
        clrscr();

        printf(“enter any two numbers:”);
        scanf(“%d%d”,&a,&b);

        big=a;
        If(big<b)
        big=b;


        printf(“big value=%d”,big);

        getch();

    }
Output:-

enter any two numbers: 5 9
big value=
9


* Write a program input three numbers & print the largest value.



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

void main()

      {

           
int a,b,c,big;
           clrscr();

           printf(“enter any three numbers:”);
           scanf(“%d%d%d”,&a,&b,&c);

           
big=a;

           If(big<b)
           big=b;

           if(big<c)
           big=c;


           printf(“big value=%d”,big);

           getch();

     }

Output:-



enter any three numbers: 7 3 5
big value=7
___________________________________________________________________________________
___________________________________________________________________________________
_____________________________________________
----------------------------------------------------------------------------------------------------------------------------------------------------------------

Greataims

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