Posts

Showing posts with the label Lab activities
Chapter # 4 (Conditional Control structure) LAB ACTIVITIES                                         1)      Write a program that reads a number and prints its square if it is greater than 10. Ans: Program: #include<stdio.h> #include<conio.h> int main(int) {             int n;             printf(“\nEnter a number:”);             scanf(“%d”, &n);             if(n>10)             printf(“\nThe square of %d is %d”, n, n*n); getch(); } Output: Enter a number:12 The square of 12 is 144. 2)      Write a progr...

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: *************************************** ...

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.   ...

Chapter # 5, Loop Control Structure, Lab Activities

Chapter # 5, Loop Control Structure                              Lab Activities Q1. Write a program to print the sum of even numbers from 1 to 50. Program: #include<stdio.h> #include<conio.h> int main(int) { int n, sum = 0; for(n=2; n<=50; n=n+2) sum=sum+n; printf(“\nSum of even numbers from 1 to 50 is %d”, sum); getch(); } Output: Sum of even numbers from 1 to 50 is 650.   Q2. Write a program to print the given sequence of numbers using a loop on a single line.         5             10           15           20           25           30       ...

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

Image
  Chapter # 4 Conditional Control structure LAB ACTIVITIES                                LONG QUESTIONS               Question 1. Write a program that reads a number and prints its square if it is greater than 10. Ans: Program: #include<stdio.h> #include<conio.h> int main(int) {             int n;             printf(“\nEnter a number:”);             scanf(“%d”, &n);             if(n>10)             printf(“\nThe square of %d is %d”, n, n*n); getch(); } Output: Enter a number:12 The square of 12 is 144. Question 2. Write a program that reads t...