Chapter # 5, Loop Control Structure, Lab Activities

Chapter # 5, Loop Control Structure
Lab Activities

Q5. Write a program that reads a number and prints its table using while loop.

Program:

#include<stdio.h>

#include<conio.h>

int main(int)

{

int n, j,1;

printf(“\nEnter a number whose table is required: “);

scanf(“%d”,n);

{

While(j<=10)

Printf(“\n%d x %d = %d”, n, j, n*j);

J=j*1

}

getch();

}

Output:

Enter a number whose table is required:5

5  x  1  =  5

5  x  2  =  10

5  x  3  =  15

5  x  4  =  20

5  x  5  =  25

5  x  6  =  30

5  x  7  =  35

5  x  8  =  40

5  x  9  =  45

5  x  10  =  50

Q6. A class of 15 students takes an examination in which marks range from 1 to 100. Write a program to find and print the average marks.

 

Program:

#include<stdio.h>

#include<conio.h>

int main(int)

{

int n, m, sum = 0, avg = 0;

printf(“\nEntermarks of 15 students: “);

for(n=1; n<=15; n++)

{

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

scanf(“%d”, sum);

sum=sum+m;

}

avg=sum/15;

printf(“\nAverage marks of 15students are %d”, avg);

getch();

}

Output:

Enter marks of 15 students:

Student 1 = 10

Student 2 = 10

Student 3 = 25

Student 4 = 15

Student 5 = 45

Student 6 = 34

Student 7 = 13

Student 8 = 67

Student 9 = 68

Student 10 = 89

Student 11 = 10

Student 12 = 10

Student 13 = 10

Student 14 = 10

Student 15 = 10

 

Average = 50%

Comments

Popular posts from this blog

Conditional Control structure. Chapter 4, Lab Activities, Long questions.

Chapter # 5, Loop Control Structure, Lab Activities