0% found this document useful (0 votes)
50 views5 pages

Control Flow - I: Laboratory

The document discusses different types of control flow statements in C programming such as if/else, switch, and loops. It provides examples of using control flow statements to check for a leap year, sum digits of a number, and calculate the product of digits. The objective is to understand how to use control flow statements to direct the order of execution in a program based on conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views5 pages

Control Flow - I: Laboratory

The document discusses different types of control flow statements in C programming such as if/else, switch, and loops. It provides examples of using control flow statements to check for a leap year, sum digits of a number, and calculate the product of digits. The objective is to understand how to use control flow statements to direct the order of execution in a program based on conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Laboratory

3
Control Flow I
Control Flow statements are if., if..else, else..if, switch.
Obecjective

In computer science, control flow (or flow of control) is the order in which individual statements,

instructions or function calls of an imperative program are executed or evaluated. The objective

of the experiment is understanding of the control flow statements in c programming language.

the procedure for finding leap year, sum and product of digits of given number .

Overview

The statements inside your source files are generally executed from top to bottom, in the order

that they appear. Control flow statements, however, break up the flowof execution by

employing decision making, looping, and branching, enabling your program to conditionally

execute particular blocks of code.

Control statements enable us to specify the flow of program control; ie, the order in which the

instructions in a program must be executed. They make it possible to make decisions, to

perform tasks repeatedly or to jump from one section of code to another.

There are four types of control statements in C:

Decision making statements

Selection statements

Iteration statements

Jump statements

Procedure
C1.1) Program For Finding Whether the Given Year is a Leap Year or not.

C1.2) Implementation of Sum of Digits of Given number ?

C1.3) Program for Computing Product of Digits Of Given Number?

Questions

1. The output of the code below is

#include <stdio.h>
void main()
{
int x = 5;
if (x < 1)
printf("hello");
if (x == 5)
printf("hi");
else
printf("no");
}
a) hi b) hello c) no d) None of the mentioned

2. The output of the code below is

#include <stdio.h>
int x;
void main()
{
if (x)
printf("hi");
else
printf("how are u");
}
a) hi b) how are you c) Compile time error d) None of the mentioned

3. Comment on the following code below

#include <stdio.h>
void main()
{
int x = 5;
if (true);
printf("hello");
}
a) It will display hello b) It will throw an error c) Nothing will be displayed
d) Compiler dependent
4. The output of the code below is

#include <stdio.h>
void main()
{
int x = 0;
if (x == 0)
printf("hi");
else
printf("how are u");
printf("hello");
}
a) hi b) how are you c) hello d) hihello

5. The output of the code below is

#include <stdio.h>
void main()
{
int x = 5;
if (x < 1);
printf("Hello");

}
a) Nothing b) Run time error c) Hello d) Varies

6. The output of the code below is(when 1 is entered)

#include <stdio.h>
void main()
{
double ch;
printf("enter a value btw 1 to 2:");
scanf("%lf", &ch);
switch (ch)
{
case 1:
printf("1");
break;
case 2:
printf("2");
break;
}
}
a) Compile time error b) 1 c) 2 d) Varies

7. The output of the code below is(When 1 is entered)

#include <stdio.h>
void main()
{
char *ch;
printf("enter a value btw 1 to 3:");
scanf("%s", ch);
switch (ch)
{
case "1":
printf("1");
break;
case "2":
printf("2");
break;
}
}
a) 1 b) 2 c) Compile time error d) No Compile time error

8. When 1 is entered, The output of the code below is?

#include <stdio.h>
void main()
{
int ch;
printf("enter a value btw 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1\n");
default:
printf("2\n");
}
}
a) 1 b) 2 c) 1 2 d) Run time error

9. When 2 is entered, The output of the code below is?

#include <stdio.h>
void main()
{
int ch;
printf("enter a value btw 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1\n");
break;
printf("Hi");
default:
printf("2\n");
}
}
a) 1 b) Hi 2 c) Run time error d) 2
10. When 1 is entered, The output of the code below is?

#include <stdio.h>
void main()
{
int ch;
printf("enter a value btw 1 to 2:");
scanf("%d", &ch);
switch (ch, ch + 1)
{
case 1:
printf("1\n");
break;
case 2:
printf("2");
break;
}
}
a)1 b) 2 c) 3 d) Run time error

Lab Report

You might also like