Chapter # 5, Loop Control Structure, Lab Activities
Chapter # 5, Loop Control Structure
Lab Activities
Q7. A class of 20 students takes
an examination in which marks range from 1 to 100. Write a program to print the
number of students passed and failed. Passing marks are 33.
Program:
#include<stdio.h>
#include<conio.h>
int main(int)
{
int n, m, pcount=0, fcount=0;
printf(“\nEnter marks of 20 students: “);
for(n=1; n<=20; n++)
{
printf(“\nstudents%d=”,m);
scanf(“%d”, &sum);
if(m>=33)
pcount=pcount + 1;
else
fcount =fcount +1;
}
printf(“\nNumber of passed students%d”, pcount);
printf(“\nNumber of fail students%d”, fcount);
getch();
}
Q8. Write a program that prints
a line of 60 asterisks (*) using do while loop.
Program:
#include<stdio.h>
#include<conio.h>
int main(int)
{
int n;
n=1
do
{
printf(“*”);
n=n+1;
for(n=1; n<=20; n++)
{
While(n<=60);
getch();
}
Output:
***************************************
Q9. Write a program that print table
of squares of all the numbers from 1 to 10 as shown below.
Number Square
1
1
2
4
3
9
4
16
5
25
6
36
7
49
8
64
9
81
10
100
Program:
#include<stdio.h>
#include<conio.h>
int main(int)
{
int n; square = 1;
for(n=1; n<=10; n++)
{
Sq=n*n;
printf(“Number\tSquare);
printf(“\n%d\t%d, n, Sq”);
}
getch();
}
Thanks sir it was very helpful
ReplyDelete