0% found this document useful (0 votes)
9 views4 pages

6. Loop

This document is a tutorial for the Department of Electronics & Communication Engineering at Dharmsinh Desai University for the academic year 2024-2025. It includes questions on programming concepts such as looping statements, control structures, and programming predictions, along with programming tasks to implement various algorithms. The tutorial is designed for B. Tech. Sem.I (EC) students to enhance their understanding of programming principles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

6. Loop

This document is a tutorial for the Department of Electronics & Communication Engineering at Dharmsinh Desai University for the academic year 2024-2025. It includes questions on programming concepts such as looping statements, control structures, and programming predictions, along with programming tasks to implement various algorithms. The tutorial is designed for B. Tech. Sem.I (EC) students to enhance their understanding of programming principles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Department of Electronics & Communication Engineering

(Faculty of Technology, Dharmsinh Desai University, Nadiad)


Academic Year : 2024 - 2025

Tutorial – 6

Subject : PPS
Class : B. Tech. Sem.I (EC)

Q.1 Select the most appropriate option.


(1) Which of the following looping statements end with a semicolon?
(a) while (b) do while (c) for (d) None of these
(2) Which of the following statements can be used to immediately exit from the program?
(a) exit()
(b) break
(c) goto
(d) Both 1 and 3
(3) A typical repetition control structure comprises which of the following parts?
(a) Initialization of condition variable
(b) Execution block
(c) Test condition and counter update instruction
(d) All of these
(4) The break statement is used to exit from:
(a) An if statement
(b) A for loop
(c) A program
(d) The main( ) function
(5) Which statement is used to skip the current iteration of a for loop and proceed to the
next iteration without executing the remaining code for that iteration?
(a) continue statement
(b) exit statement
(c) pass statement
(d) break statement
Q.2 State True or False
(1) In a preset loop, if the body is executed n terms, the test expression is executed n+1
times.
(2) While loops can be used to replace for loops without any change in the body of the
loop.
(3) An exit control loop is executed a minimum of a one line.
(4) The condition in a while loop is checked before each iteration, and if it is false initially,
the loop body will never execute.
(5) It is not possible to nest one while loop inside another while loop.
Q.3Predict the output.
(1) #include < stdio.h >
void main()
{ unsigned char var=0;
for(var=0;var<=255;var++)
{
printf("%d ",var);
}
}
(2) #include <stdio.h>
void main()
{
char cnt=0;
for(;cnt++;printf("%d",cnt)) ;
printf("%d",cnt);
}
(3) #include < stdio.h >
int main()
{
int tally=0;
for(;;)
{
if(tally==10)
break;
printf("%d ",++tally);
}
return 0;
}
(4) #include <stdio.h>
void main()
{
int i,j,charVal='A';

for(i=5;i>=1;i--)
{
for(j=0;j< i;j++)
printf("%c ",(charVal+j));
printf("\n");
}
}
(5) #include <stdio.h>
void main()
{
int cnt=1;
while(cnt>=10)
{
printf("%d,",cnt);
cnt+=1;
}
printf("\nAfter loop cnt=%d",cnt);
printf("\n");
}
(6) #include <stdio.h>
#define TRUE 1
int main()
{
int loop=10;
while(printf("Hello ") && loop--);
}
(7) #include <stdio.h>
int main()
{
int i=1;
while(i<=10 && 1++)
printf("Hello");
}
(8) int main()
{
int max = 5;
inti = 0;
for(;;)
{
i++;
if(i> max)
break;
printf("i = %d\n",i);
}
return 0;
}
(9) #include <stdlib.h>
#include <stdio.h>
enum {false, true};
int main()
{
int i = 1;
do
{
printf("%d\n", i);
i++;
if (i < 15)
continue;
} while (false);

getchar();
return 0;
}

Q.4 Do as directed.
(1) Given a number, write a program using while loop to reverse the digits of the number.
(2) Write a program to compute the sum of the digits of a given number.
(3) The numbers in the sequence1 1 2 3 5 8 13 21 …………………….are called
Fibonacci numbers. Write a program using do while loop to calculate and print the
first m Fibonacci numbers.
(4) Write a program to print the following outputs using for loops
a) 1 b) *
22 **
333 ***
(5) Write a program to compute the value of Euler’s number that is used as the base of
natural logarithms. Use the following formula.
e= 1+ 1/1! +1 /2! + 1/3+……………. 1/n!
(6) Write a program to print all integers that are not divisible by either 2 or 3 and lie
between 1 and 100. The program should also account for the number of such integers
and print
the result.

* * *

You might also like