11/16/2015
C hapter 3 - Let Us C Sol uti ons
(/)
[B] Attempt the following: (a) Write a program to calculate overtime pay of 10 employees. Overtime is paid at the rate of Rs. 12.00 per hour for every hour worked above 40 hours. Assume that employees do not work for fractional part of an hour. #include #include main() { int employ,otime,opay,hours employ,otime,opay,hours;; clrscr(); for(employ=1;employ<=10;employ++) { printf("\nEnter number of hours worked worked by %d employee employee : ",employ);
scanf("%d",&hours); if(hours>40)
{ otime=hours-40;
opay=otime*12; printf("The overtime pay of employee is %d",opay); } else if(hours<40) { printf("The is no overtime pay for employee"); } }
getch(); }
(b) Write a program to find fi nd the factorial value of any number entered through the keyboard. #include #include main() { int num; float fact=1; //num=number,fact=factorial value clrscr(); printf("Enter any number to find find its factorial factorial value : "); scanf("%d",&num); while(num>0) {
fact=fact*num; num=num-1; //decrement loop counter } printf("\nFactorial value value = %.3f",fact); %.3f",fact); // '%.3f' will will show only 3 digits after decimal decimal
getch(); }
(c) Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another. #include #include main() { int a,b,n1,n2,res=1; a,b,n1,n2,res=1; // n1=a=1st n1=a=1st number,n2=b=2nd number,n2=b=2nd number,res=result clrscr(); printf("Enter any two numbers:\n"); scanf("%d%d",&n1,&n2); a=n1; b=n2; while(n2>0) { res=res*n1; n2- -; // n2=n2-1 n2=n2-1 can also be written as n2-} printf("\n%d raised to the power %d is %d",a,b,res); getch(); }
http://letuscsol uti ons.weebly.com/chapter - 3.html
1/15
11/16/2015
Chapter 3 - Let Us C Solutions (d) Write a program to print all the ASCII values and their equivalent characters using a while loop. The ASCII values vary from 0 to 255. #include #include main() { int a=0; clrscr(); while(a<255) { printf("%d=%c ",a,a); a++; // increment statement } getch(); }
(e) Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number. For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 ) #include #include main() { int a,b,c,d,e,f,res,num =1; clrscr(); printf("Armstrong Numbers from 1 to 500\n") ; while(num<=500) {
a=num%10;
b=num/10;
c=b%10;
d=b/10;
e=d%10;
f=d/10;
if(num==(a*a*a)+(c*c*c)+(e*e*e)) {
printf("\n%d",num); }
num++; } getch(); }
(f) Write a program for a matchstick game being played between the computer and a user. Your program should ensure that the computer always wins. Rules for the game are as follows: ? There are 21 matchsticks. ? The computer asks the player to pick 1, 2, 3, or 4 matchsticks. ? After the person picks, the computer does its picking. ? Whoever is forced to pick up the last matchstick loses the game. Submitted by Rahul Raina void main( ) { int x, y, n = 21; clrscr(); printf ("The Total Amount Of Matchsticks is 21"); while(n > 1) { printf ("\nEnter Your Choice : "); scanf ("%d", &x); if((1 <= x) && (x <= 4)) { n = n - x; printf ("\nThe user chose %d, the matchsticks left %d", x, n); } else { printf ("\nWrong Entry"); break; } y = 5 - x; n = n - y; printf ("\nThe computer chose %d, the matchsticks left %d", y, n); }
http://letuscsolutions.weebly.com/chapter-3.html
2/15
11/16/2015
Chapter 3 - Let Us C Solutions if(n == 1) printf ("\nLast Match Stick Left, You Lose"); getch(); }
(g) Write a program to enter the numbers till the user wants and at the end it should display the count of positive, negative and zeros entered. #include #include main() { int num,x,p=0,n=0,z=0; /* num=number entered,x=Total numbers user want to enter p=positive numbers,n=negative numbers,z=zeros */
clrscr(); printf("How many numbers do you want to enter ? "); scanf("%d",&x); while(x>0) { scanf("%d",&num); if(num>0) p++; if(num<0) n++; if(num==0) z++; x--; } printf("\nYou Entered:\n%d Positive Numbers\n%d Negative Numbers\n%d Zeros",p,n,z); getch(); }
(h) Write a program to find the octal equivalent of the entered number. #include #include main() { long int i,num,arr[100]; // i=loop variable,num=given number,arr[100]=array clrscr(); printf("Enter any number to convert into Octal : "); scanf("%ld",&num); for(i=0;num>8;i++) {
arr[i]=num%8;
num=num/8; } printf("Octal Conversion is\n");
printf("%d",num); while(i>0) {
printf("%d",arr[i-1]);
i--;
} getch(); }
(i) Write a program to find the range of a set of numbers. Range is the difference between the smallest and biggest number in the list. Coming Soon...
[E] Attempt the following: (a) Write a program to print all prim e numbers from 1 to 300. (Hint: Use nested loops, break and continue) #include #include main() { int num,i,n=300; // num=prime numbers,n=total no. of prime numbers clrscr(); for(num=1;num<=300;num++) {
i=2;
while(i
if(num%i==0)
break;
http://letuscsolutions.weebly.com/chapter-3.html
3/15
11/16/2015
Chapter 3 - Let Us C Solutions
i++; } if(i==num)
printf("%d ",num); } getch(); }
(b) Write a program to fill the entire screen with a smiling face. The smiling face has an ASCII value 1. #include #include main() { int x=1,a=1; clrscr(); while(x<80*50) {
printf("%c",a);
x++; }
getch(); }
(c) Write a program to add first seven terms of the following series using a for loop:
#include #include main() { long double num,res,fres=0, fact=1.0; /* num=number,res=result,fres=final result,fact=factorial */
clrscr(); for(num=1.0;num<=7.0;num++) { fact=fact*num; res=num/fact; fres=fres+res; } print f("The sum of given series is %.9Lf", fres); getch(); }
(d) Write a program to generate all combinations of 1, 2 and 3 using for loop. #include #include main() { int a,b,c; clrscr(); for(a=1;a<=3;a++) {
for(b=1;b<=3;b++) {
for(c=1;c<=3;c++) {
if(a==b||b==c||a==c)
continue; else printf("%d %d %d\n",a,b,c); } }
} getch(); }
(e) According to a study, the approximate level of intelligence of a person can be calculated using the following formula: i = 2 + ( y + 0.5 x )Write a program, which will produce a table of values of i, y and x, where y varies from 1 to 6, and, for each value of y, x varies from 5.5 to 12.5 in steps of 0.5. Coming Soon...
http://letuscsolutions.weebly.com/chapter-3.html
4/15
11/16/2015
Chapter 3 - Let Us C Solutions (f) Write a program to produce the followi ng output: ABCDEFGFEDCBA ABCDEF
FEDCBA
ABCDE ABCD ABC
EDCBA DCBA CBA
AB A
BA A
#include #include main() { int a,x,n=71,o=70,y=1,c; clrscr(); for(x=1;x<=7;x++) {
for(a=65;a<=n;a++) // loop for printing A BCDEFG
printf("%c",a); if(x==2)
o=70;
for(c=2;c
printf(" "); for(a=o;a>=65;a--) // loop for printing F EDCBA
printf("\n") ; // to sta n--;
printf("%c",a);
o--;
y=y+2; }
getch(); }
(g) Write a program to fill the entire screen with diamond and heart alternatively. Th e ASCII value for heart is 3 and that of diamond is 4. #include #include main() { int a, b,c,d; clrscr(); for(c=1;c<=37;c++) {
for(d=1;d<=49;d++) {
for(a=4;a<=4;a++) {
for(b=3;b<=3;b++) printf("%c%c ",a,b); } } }
getch(); }
(h) Write a program to print the multiplicatio n table of the number entered by the user. The table should get displayed in the following form. 29 * 1 = 29 29 * 2 = 58 … #include #include main() { int res, no, a=1; // res=result,no=number,a=loop variable clrscr(); printf("Enter any number to know its table till 12 : "); scanf("%d", &no); while(a<=12) { res=a*no; printf("%d X %d = %d\n",no,a,res); a++; }
http://letuscsolutions.weebly.com/chapter-3.html
5/15
11/16/2015
Chapter 3 - Let Us C Solutions getch(); }
(i) Write a program to produce the followi ng output: 1 2 4 7
3 5
8
6 9
10
#include #include main() { int a,b,n=6; clrscr(); for(a=1;a<=10;a++) {
if(a==1||a==2||a==4||a==7) {
printf("\n");
for(b=1;b<=n;b++)
n=n-2;
printf(" "); }
printf("%4d",a); }
getch(); }
(j) Write a program to produce the following output: 1 1 1 1 1
1 2
3 4
1 3
6
1 4
1
#include #include main() { int l,a=8,i=1,s,x,y=1; clrscr(); for(l=1;l<=5;l++) { for(s=1;s<=a;s++) printf(" ");
printf("%4d",i);
if(l>=3) {
for(x=1;x<=y;x++) {
if(x==2&&y==3)
printf("%4d",l+1); else
printf("%4d",l-1); } y++; }
if(l>=2) printf("%4d",i);
a=a-2;
printf("\n"); } getch(); }
(k) A machine is purchased which will produ ce earning of Rs. 1000 per year while it lasts. The machine costs Rs. 6000 and will have a salvage of Rs. 2000 when it is condemned. If 12 percent per annum can be earned on alternate investments what would be the minimum life of the machine to make it a more attractive investment compared to alternative investment? Coming Soon...
http://letuscsolutions.weebly.com/chapter-3.html
6/15
11/16/2015
Chapter 3 - Let Us C Solutions (l) When interest compounds q times per year at an annual rate of r % for n years, the principle p compounds to an amount a as per the following formula
Write a program to read 10 sets of p, r, n & q and calculate the corresponding as. Coming Soon...
(m) The natural logarithm can be approximated by the following series.
If x is input through the keyboard, write a program to calculate the sum of first seven terms of this series. #include #include main() { in t a,b,x,y,z=1; float res,r1=1; clrscr(); printf("Enter value of x : "); scanf("%d",&x); for(a=1;a<=7;a++) { for(y=1,r1=1;y<=z;y++) {
r1=r1*(x-1)/x; }
z++; if(a>=2)
res=res+(0.5*r1);
else res=res+r1; } printf("Sum of first seven terms of given series : %f",res); getch(); } Back to Top ▲
1
46 Comments
sowjanya
•
sir give the solutions of remaining sections also...or else tell where I can find solutions •
Pratap Singh
•
•
Please add more chapters ASAP •
Amar Kaldate
•
•
The natural logarithm can be approximated by the following series. ((2-1)/2) + 0.5((2-1)/2)^2 +0.5((2-1)/2)^3 + 0.5((2-1)/2)^4 +.... If x is input through the keyboard, write a program to calculate the sum of first seven terms of this series. #include void main() { int i, j; float x, a, y , sum=0; printf("Please Enter The Value of X\t"); scanf("%f", &x);
http://letuscsolutions.weebly.com/chapter-3.html
7/15
11/16/2015
Chapter 3 - Let Us C Solutions = ; y = (x-1)/x; while(i<=7) { if(i>1) {
•
A
•
•
[E] e.According to a study, the approximate level of intelligence of a person can be calculated using the following formula: i = 2 + ( y + 0.5 x ) rite a program, which will produce a table of values of i, y and x, where y varies from 1 to 6, and, for each value of y, x varies from 5.5 to 12.5 in steps of 0.5. Ans:#include int main(int argc, char *argv[]) { float x,y,i; for(y=1;y<7;y++) { printf("value of y is %f\n",y); for(x=5.5;x<=12.5;x=x+.5) { i=2+(y+.5*x); printf("%f\t%f\n",x,i); } printf("\n\n"); } return 0; } •
Amar Kaldate
•
•
#include void main() { int n, max, min, flag=1; char ch='y'; while(ch=='y') { printf("Please Enter The no.\t"); scanf("%d",&n); while (flag==1) { max = n ; min = n ; flag=0; } if(max >= n) max = max;
•
•
Amar Kaldate
•
Above code is for Write a program to find the range of a set of numbers. Range is the difference between the smallest and biggest number in the list. •
•
sagar jyoti senapati
•
So nyc. •
Amar Kaldate
http://letuscsolutions.weebly.com/chapter-3.html
•
•
8/15
11/16/2015
Chapter 3 - Let Us C Solutions : en n eres compoun s q mes per year a an annua ra e o r or n years, the principle p compounds to an amount a as per the following formula: a = p ( 1 + r / q )^np rite a program to read 10 sets of p, r, n & q and calculate the corresponding as #include void main() { int x, i, n, p, q; float a, r, y, j; i=1; while(i<=10)
•
•
欦মাঃ ফয়সাল 欦েহাসন •
rite a program to sum first 10 terms of the following seriesy = x+x3/2 + x5/3+ ………take value of x as input and print the value of y.please i need it's solution •
igsaww
•
•
Great job but there are some answers which can be shortened and made simpler. GREAT JOB! :) •
•
priyeshwar dubey
•
good program •
Humza
•
•
for other programs you have two pay fees, hain na irtiqa ji •
Humza
•
•
HHmmmm/............./Professor Irtiqa is making programs •
•
Ahsan
•
Kindly Add more Programs if you can so that more and more people can get benefit from it. I personally Learnt alot. Thanks •
megha
•
•
// B(PART I)-program to find range #include #include void main() { int max=0,min=0,n,a[20],i; printf("enter how much numbers u want"); scanf("%d",&n); printf("enter the no"); for(i=0;ia[i]) min=a[i]; }printf("min is\n%d",min); printf("range is %d\n",max-min); getch();
http://letuscsolutions.weebly.com/chapter-3.html
9/15
11/16/2015
Chapter 3 - Let Us C Solutions •
•
sagar jyoti senapati
•
Nyc •
Akhtar Khan
•
•
hankyou sir •
•
Shantanu Pathak
•
Question no: E #include void main() { float i,y,x; printf("APPROXIMATION OF INTELLIGENCE"); printf("\n"); printf("\n"); for(y=1;y<=6;y++) { =
<=
•
Pankaj Naik
= +
•
•
#include main() { int y ; float i, x ; printf("___________________________________\n\n") ; printf("\ty\tx\ti\n") ; printf("___________________________________") ; for ( y = 1 ; y <= 6 ; y++ ) { for x = 5.5 x <= 12.5 x = x + 0.5
•
Siraj
•
•
Answer of Question E (e). #include #include void main() { float x,y; for(y=1;y<=6;y++) {
http://letuscsolutions.weebly.com/chapter-3.html
10/15
11/16/2015
Chapter 3 - Let Us C Solutions for(x=5.5;x<=12.5;x=x+0.5) { printf("\ni = %f", 2+(y+(0.5*x))); } } getch(); } •
•
naveed chauhan
•
Q 1: Write a program to check if a number input by user is PRIME or not, range of input is 1 to 300. •
ejaswini
•
•
1 22 33 3 4444 55555 Tsis is output plz give me ans anyone •
•
Dhiman Mridha
•
Problem [E] (f) can also be solved like this. Lot more easier. :) #include main () { int a=1; printf("\n"); for (a;a<2;a++) { printf("A B C D E F G F E D C B A"); } printf("\n");
•
•
Dhiman
•
hy the space between the code does not show :( •
Dhiman Mridha
•
•
Problem [E] (f) can also be solved like this. It's lot more easier, try this. #include main () { int a=1; printf("\n"); for (a;a<2;a++) {
http://letuscsolutions.weebly.com/chapter-3.html
11/15
11/16/2015
Chapter 3 - Let Us C Solutions printf("A B C D E F G F E D C B A"); } printf("\n");
•
•
Dhiman Mridha
•
Problem [E] (a) can also be solved by this. I used two integer insted three as admin did. #include main () { int a,b; printf("All the prime numbers between 1 to 300 are given below : \n"); for (a=1;a<=300;a++) { b=2; while (b<=a-1)
•
•
Dhiman Mridha
•
There is a mistake in [E] (a) inside while it must be (i<=n-1) Admin has given (i •
Rohan Khan
•
•
another 1 for printing alphabets order: #include #include main() { int y,sp; char a,x; a=71; /*ASCII value of G stored in a*/ for (y=1;y<=7;y++) /*primary test is independent of a*/ { for x =65 x<=a x++ /*for rintin ABCD... in increasin order*/
•
•
chetan raikwar
•
solutions to let us C. http://letuscalllessons.blogsp... •
yusra rehan
•
•
plz help me to understand these programs....... •
http://letuscsolutions.weebly.com/chapter-3.html
•
12/15
11/16/2015
Chapter 3 - Let Us C Solutions Guest
•
#include void main() { int s=6; for(int a=1;a<=10;a++) { if(a==1||a==2||a==4||a==7) { cout< •
Guest
•
•
Chapter 3 [E] (i) (i) Write a program to produce the following output: 1 23 45 6 7 8 9 10 #include void main() { int s=6; for(int a=1;a<=10;a++) { if(a==1||a==2||a==4||a==7) { cout< •
•
noor fatima
•
kindly give the solutions of remaining questions or tell me where i can find these solutions •
•
Asad.ur.Rehman
•
MOstly programes are incorrect..... please use correctly code for GOD says.. please please if not then turn off this website thanks.. why drop the future of youngest with your wrong code? why you destring the future of youngest by this wrong programming....? All programmes includes most errors... please use correct coding Thanks....... •
utkarsh
•
•
in ques [B] h.) he condtion in for loop will be.. for(i=0;num!=0;i++) not for(i=0;num>0;i++) •
ali
•
•
i didn't get the idea of question (i) •
Gayathri
•
•
THANKS ALOT •
robin
•
•
very helpfull programs........... •
http://letuscsolutions.weebly.com/chapter-3.html
•
13/15
11/16/2015
Chapter 3 - Let Us C Solutions muhammad usman
•
hnkzzzzz !!! all prgrm are amazing !!! and very helpfull :P :P :P •
ali
•
•
is E (F) working ? •
TAYYAB
•
•
nice programs.....i easily understand it....thanks to professor who made it... •
Priya Patidar
•
•
To this programs thanks and pleas add more chapter •
•
mysteriouszem
•
great job thanks •
Shaker Shafi
•
•
qustion (i) #include void p_factor(int); void main() { int no, factor; printf("Please Enter The no\t"); scanf("%d", &no); p_factor(no); } void p_factor(int a) { int i=2, j= a; while(i<=j) { if (j%i==0) { =j/i; printf(" %d ", i); } else i++; } } •
•
ones jude
•
e use high quality equipment and materials to produce our counterfeit documents but we do real documents as well. All secret features of real passports are carefully duplicated for our falsified documents but real documents are backed in the data base meaning they can be renewed legally. We offer original high-quality fake and original Passports, Diplomatic Passports, Driver's Licenses, ID cards, Stamps, Visas, School Diplomas e.t.c.For a number of countries like: USA(United States), Australia, Canada, UK (United Kingdom), Germany, Belgium, France, Brazil, Finland, Netherlands, Israel, Spain, Italy, Mexico, South Africa, Austria, Bahrain, Argentina, India, China, Hong Kong and any other country that you require. so if interested , get back to us for more information •
SALMAN ALI
•
•
very interesting solutions.... thanks the uploader!! •
http://letuscsolutions.weebly.com/chapter-3.html
•
14/15
11/16/2015
http://letuscsolutions.weebly.com/chapter-3.html
Chapter 3 - Let Us C Solutions
15/15