This website contains solutions of Let Us C Programs Chapter 1:- Getting Started Chapter 2:- The Decision Control Structure Chapter 3:- The loop Control Structure Chapter 4:- The Case Control Structure Chapter 5:- Functions & Pointers. Tamilnadu Samacheer Kalvi 8th Science Solutions Term 1 Chapter 4 Matter. Used by the ancient Greeks to represent the four basic elements around us such as earth.
- Chapter 4 Completedlet Us C Solutions Llc
- Chapter 4 Completedlet Us C Solutions Inc
- Chapter 4 Completedlet Us C Solutions Pvt Ltd
- Chapter 4 Completedlet Us C Solutions Collection Agency
Exercise [C]
Write a menu driven program which has following options:
1. Factorial of a number.
2. Prime or not
3. Odd or even
4. Exit
Solution:
#include<stdio.h>
#include<conio.h>
main() {
int num,i,j=0,k=0,choice,fact=1;
clrscr();
printf('Please enter any number: ');
scanf('%d',&num);
while(1)
{
printf('nn1. Factorial');
printf('n2. Prime');
printf('n3. Odd/Even');
printf('n4. Exit');
printf('nnPlease enter your choice: ');
scanf('%d',&choice);
switch(choice)
{
case 1:
for(i=num;i>=1;i--) {
fact=fact*i;
}
printf('nFactorial = %d ',fact);
break;
case 2:
for(i=2;i<num;i++) {
j=num%i;
if(j0){
k=1;
break;
}
}
if(k0) {
printf('nPrime Number');
}
else {
printf('nNot a Prime Number');
}
break;
case 3:
if((num%2)0)
printf('nEven Number');
else
printf('nOdd Number');
break;
case 4:
exit();
}
Chapter 4 Completedlet Us C Solutions Llc
}}
------------------------------------------------------------------------------------------------------------
Exercise [D]
Write a program which to find the grace marks for a student using switch. The user should enter the class obtained by the student and the number of subjects he has failed in.
− If the student gets first class and the number of subjects he failed in is greater than 3, then he does not get any grace. If the number of subjects he failed in is less than or equal to 3 then the grace is of 5 marks per subject.
− If the student gets second class and the number of subjects he failed in is greater than 2, then he does not get any grace. If the number of subjects he failed in is less than or equal to 2 then the grace is of 4 marks per subject.
− If the student gets third class and the number of subjects he failed in is greater than 1, then he does not get any grace. If the number of subjects he failed in is equal to 1 then the grace is of 5 marks per subject
Solution:
#include<stdio.h>
#include<conio.h>
main() {
int _class,f_sub;
clrscr();
printf('nPlease enter the class obtainedn1=first 2=second 3=third: ');
scanf('%d',&_class);
printf('nnPlease enter the number of failed subjects: ');
scanf('%d',&f_sub);
switch(_class) {
case 1:
if(f_sub<=3) {
printf('nGrace marks = 5 marks per subject.n');
Chapter 4 Completedlet Us C Solutions Inc
}
else {
printf('nNo Grace marks.n');
}
break;
case 2:
if(f_sub<=2) {
printf('nGrace marks = 4 marks per subject.n');
}
else {
printf('nNo Grace marks.n');
}
break;
case 3:
if(f_sub1) {
printf('nGrace marks = 5 marks per subject.n');
}
else {
Chapter 4 Completedlet Us C Solutions Pvt Ltd
printf('nNo Grace marks.n');
}
break;
default:
printf('Error! wrong input.n');
break;
}
Chapter 4 Completedlet Us C Solutions Collection Agency
getch();return 0;
}
_____________________________________________________________________
Question-
Write a menu driven program which has following options:
1. Factorial of a number.
2. Prime or not
3. Odd or even
4. Exit
solution-very easy.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,fact=1,num,j;
printf('Menu Driven Programn');
printf('1.Factorialn');
printf('2.Primen');
printf('3.Odd/Evenn');
printf('4.Exitn');
printf('Enter your choice[Enter digit]n');
scanf('%d',&i);
switch(i)
{
case 1:
printf('Enter any numbern');
scanf('%d',&num);
for(j=1;j<=num;j++)
fact=fact*j;
printf('Factorial value=%dn',fact);
break;
case 2:
printf('Enter Any Numbern');
scanf('%d',&num);
for(j=2;j<=num-1;j++)
{
if(num%j0)
{
printf('It's not a prime numbern');
break;
}
}
if(numj)
printf('It is a prime numbern');
break;
case 3:
printf('Enter Any Numbern');
scanf('%d',&num);
num%20?printf('Even numbern'):printf('Odd Numbern');
break;
case 4:
return 0;
}
}
Write a menu driven program which has following options:
1. Factorial of a number.
2. Prime or not
3. Odd or even
4. Exit
solution-very easy.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,fact=1,num,j;
printf('Menu Driven Programn');
printf('1.Factorialn');
printf('2.Primen');
printf('3.Odd/Evenn');
printf('4.Exitn');
printf('Enter your choice[Enter digit]n');
scanf('%d',&i);
switch(i)
{
case 1:
printf('Enter any numbern');
scanf('%d',&num);
for(j=1;j<=num;j++)
fact=fact*j;
printf('Factorial value=%dn',fact);
break;
case 2:
printf('Enter Any Numbern');
scanf('%d',&num);
for(j=2;j<=num-1;j++)
{
if(num%j0)
{
printf('It's not a prime numbern');
break;
}
}
if(numj)
printf('It is a prime numbern');
break;
case 3:
printf('Enter Any Numbern');
scanf('%d',&num);
num%20?printf('Even numbern'):printf('Odd Numbern');
break;
case 4:
return 0;
}
}