Chapter 4 Completedlet Us C Solutions



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;
}
}


Exercise [C]

NCERT Solutions for Class 6 Social Science History Chapter 4- “What Books and Burials Tell Us” The solutions for Chapter 4, In the Earliest Cities are given below. Students should also check NCERT Solutions for Class 6 for other subjects. Exercise Questions Page No. Let Us C Solutions of chapter 4 The Loop control structure. Often in computer programming, it is necessary to perform a certain action a certain number of times or until a certain condition is met. Kimi no na wa download reddit. The constructs that enable computers to perform certain repetitive tasks are called loops. Mr. gimmick 2. Very useful information. A while loop is the most basic type of loop.


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;

Chapter 4 Completedlet Us C Solutions Llc

case 3:

if((num%2)0)
printf('nEven Number');
else
printf('nOdd Number');
break;

case 4:

exit();

}
}

}
------------------------------------------------------------------------------------------------------------

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:

Chapter 4 Completedlet Us C Solutions Inc


#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);

Completedletswitch(_class) {

case 1:
if(f_sub<=3) {
printf('nGrace marks = 5 marks per subject.n');
}Solutions
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 {
printf('nNo Grace marks.n');Llc
}
break;

default:
printf('Error! wrong input.n');
break;
}

getch();
return 0;

}
_____________________________________________________________________