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...
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: *************************************** ...
Comments
Post a Comment