C - Control statement

C Language

Control statement



Fill in the blanks

1.  How many control statement presents in c   3

2.  While is   Entry controlled loop

3.  Do while is Exit controlled loop

4.  Write a expansion for stdio.h  standard input output

5.  Write a expansion for conio.h  console input output

6.  Write a syntax for for loop   for(initialization;condition checking;inc/dec)

7.  Getch presents in which header file  conio.h

8.  Printf presents in conio.h.[T/F]    False

9.  Clrscr presents in stdio.h  [T/F]    False

10.       What is the output for below condition

   for(int i=0;i<=8;i++)

{

if(i==4)

break;

}

Output   :    123

Answer the following Questions

                                                            (4 Marks)

 

1.Difference between while and do-while

While Loop

Do-While Loop

Entry Controlled Loop

Exit Controlled Loop

While loop is pretested loop

Do-while is post tested loop

Syntax

while(condition){

Statement;

}

Syntax

do{

statement;

}while(condition);

#include<stdio.h>

#include<conio.h>

main(){

int a=5;

clrscr();

while(a<5){

printf(“%d”,a);

a++;

}

getch();

}

#include<stdio.h>

#include<conio.h>

main(){

int a=5;

clrscr();

do{

printf(“%d”,a);

a++;

} while(a<5);

getch();

}

2.Write a program for leap year and not leap year

#include<stdio.h>

#include<conio.h>

main()

{

int  a;

clrscr();

printf(“enter any year”);

scanf(“%d”,&a);

if(a%4==0){

printf(“Leap year”);

}

else{

printf(“Not Leap Year”);

}

getch();

}

3.Write a program for age verification program

#include<stdio.h>

#include<conio.h>

main()

{

int  a;

clrscr();

printf(“enter your age”);

scanf(“%d”,&a);

if(a>=18){

printf(“Eligible for vote”);

}

else{

printf(“Not eligible for vote”);

}

getch();

}

4.Write a program to print pass or fail using if else

#include<stdio.h>

#include<conio.h>

main()

{

int  a;

clrscr();

printf(“enter your mark”);

scanf(“%d”,&a);

if(a>=50){

printf(“Pass”);

}

else{

printf(“Fail”);

}

getch();

}

5.To print 1 to 100 using for loop

#include<stdio.h>

#include<conio.h>

main()

{

int i;

clrscr();

for(i=1;i<=100;i++){

printf(“%d\n”,i);

}

getch();

}

6.Difference between break and continue

 BREAK

 

Syntax

  break;

 

program:

 

#include<stdio.h>

#include<conio.h>

main()

{

int;

clrscr();

for(i=0;i<=10;i++)

{

if(i==5)

break;

printf("%d",i)

}

getch();

}

 

Continue                                 

 Syntax:

    continue

 

program:

#include<stdio.h>

#include<conio.h>

main()

{

int i;

clrscr();

for(i=0;i<=10;i++)

{

if(i==5)

continue;

printf("%d",i)

}

getch();

}

7.Write a program for return and goto

Return

return statement used to return from a function

syntax

return expression;

eg.return o;          

program

#include<stdio.h>

#include<conio.h>

int    main()

{    

clrscr();

printf("hi hello");

return 0;

}

Goto

syntax

goto statement-lable;

 

program

#include<stdio.h>

#include<conio.h>

main()

{

int x=5,y=3;

if(x==y)

{

printf("EQUAL");

}

else{

goto ERROR;

ERROR:

printf("not equal")

}

getch();

}

8.Write a program to print no of days using switch case

 

#include<stdio.h>

#include<conio.h>

main()

{

int d;

clrscr();

printf("enter day");

scanf("%d",&d);

switch(d)

{

case 1:

printf("sunday");

break;

case 2:

printf("Monday");

break;

case 3:

printf("Tuesday");

break;

case 4:

printf("Wednesday");

break;

case 5:

printf("Thursday"));

break;

case 6:

printf("Friday");

break;

case 7:

printf("Saturday");

break;

default:

printf("enter valid number");

}

getch();

}


Answer the following Questions

                                                            (10 Marks)

 

1.Write a program to print student marklist with grade system using Nested if

#include<stdio.h>

#include<conio.h>

main()

{

int m;

clrscr();

printf("enter your mark");

scanf("%d",&m);

if (m>=50)

{

if (m>=80)

{

printf("a grade");

]

else{

printf("b grade");

}

}

else

{

if(m>=30)

{

printf("c grade");

}

else{

printf("fail");

}

}

getch();

}

2. Explain the below control statements program

*While

*do while

* if

*Break

*continue

*goto

while loop

                             (entry controlled loop)   

 

syntax:

            while (condition)

            {

            statement;

            }

program:

#include<stdio.h>

#include<conio.h>

main()

{

int i=5;

clrscr();

while(i<5)

{

printf("%d",i);

i++;

}

getch();

}

 

Do - While (Exit controlled loop)

syntax:

do{

statement;   

}

while(condition);

 

program:

 

#include<stdio.h>

#include<conio.h>

main()

{

int i=5;

clrscr();

do(

printf("%d",i);

i++;

}

while(i<5);

getch();

}

 

#include <stdio.h>

#include<conio.h>

main()

{

int m;

clrscr();

printf("enter your mark");

scanf("%d",&m);                                  

if(m>=50)                                              

{                                                              

printf("pass");                                       

}                                                              

if(m<50)                                                 

{

printf("fail");

}

getch();

}

BREAK

 

Syntax

  break;

 

program:

 

#include<stdio.h>

#include<conio.h>

main()

{

int;

clrscr();

for(i=0;i<=10;i++)

{

if(i==5)

break;

printf("%d",i)

}

getch();

}

 

Continue                                 

 Syntax:

    continue

 

program:

#include<stdio.h>

#include<conio.h>

main()

{

int i;

clrscr();

for(i=0;i<=10;i++)

{

if(i==5)

continue;

printf("%d",i)

}

getch();

}

Goto

syntax

goto statement-lable;

 

program

#include<stdio.h>

#include<conio.h>

main()

{

int x=5,y=3;

if(x==y)

{

printf("EQUAL");

}

else{

goto ERROR;

ERROR:

printf("not equal")

}

getch();

}

No comments:

Post a Comment