Chapter 4 – Gender, Religion and Caste. In the NCERT solutions for Chapter 4, revise the topic of gender-based discrimination. Learn about communal politics with suitable examples from the past. Also, gain awareness on the role of caste and gender in politics with our model answers. Chapter 5 – Popular Struggles and Movements. The new solutions will be uploaded there, I will try to come up with Solutions of some other popular programming books.:) Suggestions are always welcome. Let Us C / Chapter. Consider the Simulink model in Task 1. Let a be the sum of the last digits of your student numbers of the group. For example Student nr.1: XXXXX2 Student nr.2: XXXXX7 Then a = 2 + 7 = 14 (1) Build a Simulink file for the feedback control system in Fig.1 and name your group's simulink file as 1E474Fa2020T1simStudentNames.mdl.
[H]write C programs for the following:(a)Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.
click here for Answer!!!
Answer:
main()
{
float bs,gs;
printf('nInput Basic Salary');
scanf('%f',&bs);
gs=bs*(16.0/10.0);
printf('nGross Salary is %f',gs);
}
(b)The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.
click here for Answer!!!
Answer :
main()
{
float distance,distancem,distancefeet,distanceinches,distancecm;
printf('nInput distance in km');
scanf('%f',&distance);
distancem= distance*1000.0;
distancefeet= distancem*3.2808;
distanceinches= (distance*100000.0)/2.54;
distancecm = distance*100000.0;
printf('n Distance in metres = %fmn Distance in feet = %fftn Distance in inches = %finchesn Distance in cm = %fcm',distancem,distancefeet,distanceinches,distancecm);
}
(c) If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.
click here for Answer!!!
main()
{
float a,b,c,d,e,t,am,pm;
printf('nInput the 5 test marks followed by total obtainable marks');
scanf('%f%f%f%f%f%f',&a,&b,&c,&d,&e,&t);
am=(a+b+c+d+e)/5;
pm=(am/t)*100.0;
printf('nThe aggregate marks is %fnThe percentage marks is %f',am,pm);
}
(d)Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade degrees.
click here for Answer!!!
Answer:
main()
{
float c,f;
printf('nInput the temperate(Fahrenheit)');
scanf('%f',&f);
c= (f-32)*(100.0/180.0);
printf('nThe temperature in Celsius is %f',c);
}
(e) The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.
click here for Answer!!!
void main()
{
float l,b,r,arear,perimeterr,areac,perimeterc;
printf('nInput the length and breadth of rectangle and radius of circle respectively');
scanf('%f%f%f',&l,&b,&r);
arear=l*b;
perimeterr=2*l+2*b;
areac=3.141592654*r*r;
perimeterc=2*3.141592654*r;
printf('nThe area of rectangle is %fnThe perimeter of rectangle is %fnThe area of circle is %fnThe circumference of the circle is %f',arear,perimeterr,areac,perimeterc);
}
(f) Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.
click here for Answer!!!
void main()
{
float c,d,e,f;
printf('nInput values of C and D');
scanf('%f%f',&c,&d);
e=c;
f=d;
c=f;
d=e;
printf('nNow C is %fnD is %f',c,d);
}
(g) If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits.
(Hint: Use the modulus operator ‘%’)
click here for Answer!!!
Answer:
void main()
{
float number,a,b,c,d,e;
int a1,b1,c1,d1,e1,t;
printf('nKey in a five digit number');
scanf('%f',&number);
a=number/10000.0;
a1=a/1;
b=(number-(a1*10000.0))/1000;
b1=b/1;
c=(number-(a1*10000.0)-(b1*1000))/100;
c1=c/1;
d=(number-(a1*10000.0)-(b1*1000)-(c1*100))/10;
d1=d/1;
e=(number-(a1*10000.0)-(b1*1000)-(c1*100)-(d1*10))/1;
e1=e/1;
t=a1+b1+c1+d1+e1;
printf('nThe sum of the five digits is %d',t);
}
(h) If a five-digit number is input through the keyboard, write a program to reverse the number.
click here for Answer!!!
Answer:
void main()
{
float a,b,c,d,e,t,a2,b2,c2,d2,e2,s;
int a1,b1,c1,d1,e1;
printf('nInput a 5 digit number');
scanf('%f',&t);
a=t/10000.0;
a1=a;
b=(t-(a1*10000.0))/1000;
b1=b;
c=(t-(a1*10000.0)-(b1*1000))/100;
c1=c;
d=(t-(a1*10000.0)-(b1*1000)-(c1*100))/10;
d1=d;
e=t-(a1*10000.0)-(b1*1000)-(c1*100)-(d1*10);
e1=e;
a2=e1*10000.0;
b2=d1*1000.0;
c2=c1*100.0;
d2=b1*10.0;
e2=a1*1.0;
s=a2+b2+c2+d2+e2;
printf('nThe required result is %f',s);
}
(i) If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number.
click here for Answer!!!
Answer:
void main()
{
float a,d,t;
int a1,d1,t1,u;
printf('nInput a 4 digit number');
scanf('%f',&t);
a=t/1000.0;
u=t;
a1=a;
d=u%10;
d1=d;
t1=a1+d1;
printf('nThe Sum f %d',t1);
}
(k) A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is input through the keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the withdrawer.
click here for Answer!!!
Answer:
Note: So if its $900 the input value is 9 and if its $1970 input is 19.7
void main()
{
float t,_10,_50,_100;
int _11,_51,_101;
printf('nInput notes in hundreds');
scanf('%f',&t);
_100=t/100;
_101=_100;
_50=(t-_101*100.0)/50;
_51=_50;
_10=(t-(_101*100.0+_51*50.0))/10;
_11=_10;
printf('n_100 is %fn_101 is %d',_100,_101);
printf('nThe no of $100 notes is %dnThe no of $50 notes is %dnThe no of $10 notes is %d',_101,_51,_11);
}
(l) If the total selling price of 15 items and the total profit earned on them is input through the keyboard, write a program to find the cost price of one item.
click here for Answer!!!
Answer:
void main()
{
float sp,tp,cp,cps;
printf('nInput the total selling price of 15 itmes and total profit earned respectively');
scanf('%f%f',&sp,&tp);
cps=sp-tp;
printf('nThe cost price of one item is %f',cp=cps/15.0);
}
(m) If a five-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example if the number that is input is 12391 then the output should be displayed as 23402.
click here for Answer!!!
void main()
{
float s,t;
int a,b,c,d,e;
printf('nInput a 5 digit number');
scanf('%f',&t);
a=t/10000.0;
b=(t-(a*10000.0))/1000;
c=(t-(a*10000.0)-(b*1000))/100;
d=(t-(a*10000.0)-(b*1000)-(c*100))/10;
e=(t-(a*10000.0)-(b*1000)-(c*100)-(d*10))/1;
a+=1;
b+=1;
c+=1;
d+=1;
e+=1;
if (a10)
a=0;
if (b10)
b=0;
if (c10)
c=0;
if (d10)
d=0;
if (e10)
e=0;
s=(a*10000.0)+(b*1000.0)+(c*100.0)+(d*10.0)+(e);
printf('nThe required result is %f',s);
}
(a)Write a function to calculate the factorial value of any integer entered through
the keyboard.
Chapter 1let Us C Solutions Corp
Answer:#include
main()
{
int i, f;
int factorial();
printf('Enter the number to evaluate its factorial:');
scanf ('%d', &i);
f=factorial(i);
printf('%d! = %dn', i, f);
}
factorial(int num)
{
int temp, fact;
for (temp=1,fact=1;temp<=num; temp++) { fact=fact*temp; continue; } return (fact); }
main()
{
int i, f;
int factorial();
printf('Enter the number to evaluate its factorial:');
scanf ('%d', &i);
f=factorial(i);
printf('%d! = %dn', i, f);
}
factorial(int num)
{
int temp, fact;
for (temp=1,fact=1;temp<=num; temp++) { fact=fact*temp; continue; } return (fact); }
Answer : #include
main()
{
int power (a,b);
int a, b, result;
printf('Enter the value of a and b:');
scanf ('%d %d', &a, &b);
result=power(a,b);
printf('%d raised to %d is %d', a, b, result);
}
power (int a, int b)
{
int calculation=1, calc;
for (calc=1; calc <=b; calc++) { calculation=calculation*a; continue; } return(calculation); }
main()
{
int power (a,b);
int a, b, result;
printf('Enter the value of a and b:');
scanf ('%d %d', &a, &b);
result=power(a,b);
printf('%d raised to %d is %d', a, b, result);
}
power (int a, int b)
{
int calculation=1, calc;
for (calc=1; calc <=b; calc++) { calculation=calculation*a; continue; } return(calculation); }
Chapter 1 Let Us C Solutions
The following table shows the roman equivalents of decimal numbers:
Decimal:........Roman
1.....................i
5....................v
10..................x
50..................l
100................c
500...............d
1000.............m
Example:
Romanequivalent of 1988 is mdcccclxxxviii
Roman equivalent of 1525 is mdxxv
Answer:#include
main()
{
int year;
int convert (int year);
{
printf('Note:Enter a four year digit year.nn');
printf('Enter the year that you wanna convert to Roman: ' );
scanf ('%d', &year);
if (year> 1999)
{
printf('Invalid Year.Please enter again.nn');
}
}
convert(year);
}
convert(int year)
{
int i;
printf('nYear converted to Roman:');
i=(year/1000); //thousands place
if(i1)
{
printf('m');
}
i=((year/100)%10); //hundreds place
switch (i)
{
case 1:
printf('c');
break;
case 2:
printf('cc');
break;
case 3:
printf('ccc');
break;
case 4:
printf('cd');
break;
case 5:
printf('d');
break;
case 6:
printf('dc');
break;
case 7:
printf('dcc');
break;
case 8:
printf('dccc');
break;
case 9:
printf('dcccc'); //this part you may think is wrong..9 -> cm
break; //but i have taken a hint from the example in the question.
}
i=((year/10)%10); //tens place
switch(i)
{
case 1:
printf('x');
break;
case 2:
printf('xx');
break;
case 3:
printf('xxx');
break;
case 4:
printf('xl');
break;
case 5:
printf('l');
break;
case 6:
printf('lx');
break;
case 7:
printf('lxx');
break;
case 8:
printf('lxxx');
break;
case 9:
printf('lxxxx'); //had it not been for this example, it would have been xc
break;
}
i=year%10; //ones place
switch(i)
{
case 1:
printf('i');
break;
case 2:
printf('ii');
break;
case 3:
printf('iii');
break;
case 4:
printf('iv');
break;
case 5:
printf('v');
break;
case 6:
printf('vi');
break;
case 7:
printf('vii');
break;
case 8:
printf('viii');
break;
case 9:
printf('ix');
break;
}
printf ('nn');
return 0;
}
main()
{
int year;
int convert (int year);
{
printf('Note:Enter a four year digit year.nn');
printf('Enter the year that you wanna convert to Roman: ' );
scanf ('%d', &year);
if (year> 1999)
{
printf('Invalid Year.Please enter again.nn');
}
}
convert(year);
}
convert(int year)
{
int i;
printf('nYear converted to Roman:');
i=(year/1000); //thousands place
if(i1)
{
printf('m');
}
i=((year/100)%10); //hundreds place
switch (i)
{
case 1:
printf('c');
break;
case 2:
printf('cc');
break;
case 3:
printf('ccc');
break;
case 4:
printf('cd');
break;
case 5:
printf('d');
break;
case 6:
printf('dc');
break;
case 7:
printf('dcc');
break;
case 8:
printf('dccc');
break;
case 9:
printf('dcccc'); //this part you may think is wrong..9 -> cm
break; //but i have taken a hint from the example in the question.
}
i=((year/10)%10); //tens place
switch(i)
{
case 1:
printf('x');
break;
case 2:
printf('xx');
break;
case 3:
printf('xxx');
break;
case 4:
printf('xl');
break;
case 5:
printf('l');
break;
case 6:
printf('lx');
break;
case 7:
printf('lxx');
break;
case 8:
printf('lxxx');
break;
case 9:
printf('lxxxx'); //had it not been for this example, it would have been xc
break;
}
i=year%10; //ones place
switch(i)
{
case 1:
printf('i');
break;
case 2:
printf('ii');
break;
case 3:
printf('iii');
break;
case 4:
printf('iv');
break;
case 5:
printf('v');
break;
case 6:
printf('vi');
break;
case 7:
printf('vii');
break;
case 8:
printf('viii');
break;
case 9:
printf('ix');
break;
}
printf ('nn');
return 0;
}
Answer: #include
main()
{
int leap_year(year);
int year, lp;
printf('Enter the year:');
scanf ('%d', &year);
lp=leap_year(year);
if (lp)
{
printf('nThe entered year is a leap year.');
}
else
{
printf('nThe entered year is not a leap year.');
}
}
leap_year(int y)
{
int lp;
if (y%40)
{
lp=1;
}
else
lp=0;
return(lp);
}
main()
{
int leap_year(year);
int year, lp;
printf('Enter the year:');
scanf ('%d', &year);
lp=leap_year(year);
if (lp)
{
printf('nThe entered year is a leap year.');
}
else
{
printf('nThe entered year is not a leap year.');
}
}
leap_year(int y)
{
int lp;
if (y%40)
{
lp=1;
}
else
lp=0;
return(lp);
}
Chapter 1let Us C Solutions Llc
Answer:#include
main()
{
int number;
int prime(int number);
int primefactor(int number);
printf('Enter the number whose prime factors are to be calculated:');
scanf ('%d', &number);
primefactor(number);
}
//The following function detects a Prime number.
prime(int num)
{
int i, ifprime;
for (i=2; i<=num-1; i++)
{
if (num%i0)
{
ifprime=0;
}
else
ifprime=1;
}
return
(ifprime);
}
//The following function prints the prime factors of a number.
primefactor(int num)
{
int factor,ifprime;
for (factor=2; factor<=num;
)
{
prime(factor);
//so that the factors are only prime and nothing else.
if (ifprime)
{
if(num%factor0) //diving by all the prime numbers less than the number itself.
{
printf('%d ', factor);
num=num/factor;
continue;
}
else
{
factor++;//this cannot be made a part of the for loop
}
}
}
return 0;
}
main()
{
int number;
int prime(int number);
int primefactor(int number);
printf('Enter the number whose prime factors are to be calculated:');
scanf ('%d', &number);
primefactor(number);
}
//The following function detects a Prime number.
prime(int num)
{
int i, ifprime;
for (i=2; i<=num-1; i++)
{
if (num%i0)
{
ifprime=0;
}
else
ifprime=1;
}
return
(ifprime);
}
//The following function prints the prime factors of a number.
primefactor(int num)
{
int factor,ifprime;
for (factor=2; factor<=num;
)
{
prime(factor);
//so that the factors are only prime and nothing else.
if (ifprime)
{
if(num%factor0) //diving by all the prime numbers less than the number itself.
{
printf('%d ', factor);
num=num/factor;
continue;
}
else
{
factor++;//this cannot be made a part of the for loop
}
}
}
return 0;
}