Anda di halaman 1dari 15

11/16/2015

Chapter3LetUsCSolutions

(/)

[B]Attemptthefollowing:
(a)Writeaprogramtocalculateovertimepayof10employees.Overtimeispaidattherateof
Rs.12.00perhourforeveryhourworkedabove40hours.Assumethatemployeesdonot
workforfractionalpartofanhour.
#include<stdio.h>
#include<conio.h>
main()
{
intemploy,otime,opay,hours
clrscr()
for(employ=1employ<=10employ++)
{
printf("\nEnternumberofhoursworkedby%demployee:",employ)
scanf("%d",&hours)
if(hours>40)
{
otime=hours40
opay=otime*12
printf("Theovertimepayofemployeeis%d",opay)
}
elseif(hours<40)
{
printf("Theisnoovertimepayforemployee")
}
}
getch()
}

(b)Writeaprogramtofindthefactorialvalueofanynumberenteredthroughthekeyboard.
#include<stdio.h>
#include<conio.h>
main()
{
intnum
floatfact=1//num=number,fact=factorialvalue
clrscr()
printf("Enteranynumbertofinditsfactorialvalue:")
scanf("%d",&num)
while(num>0)
{
fact=fact*num
num=num1//decrementloopcounter
}
printf("\nFactorialvalue=%.3f",fact)//'%.3f'willshowonly3digitsafterdecimal
getch()
}

(c)Twonumbersareenteredthroughthekeyboard.Writeaprogramtofindthevalueofone
numberraisedtothepowerofanother.
#include<stdio.h>
#include<conio.h>
main()
{
inta,b,n1,n2,res=1//n1=a=1stnumber,n2=b=2ndnumber,res=result
clrscr()
printf("Enteranytwonumbers:\n")
scanf("%d%d",&n1,&n2)
a=n1
b=n2
while(n2>0)
{
res=res*n1
n2//n2=n21canalsobewrittenasn2
}
printf("\n%draisedtothepower%dis%d",a,b,res)
getch()
}

http://letuscsolutions.weebly.com/chapter3.html

1/15

11/16/2015

Chapter3LetUsCSolutions
(d)WriteaprogramtoprintalltheASCIIvaluesandtheirequivalentcharactersusingawhile
loop.TheASCIIvaluesvaryfrom0to255.
#include<stdio.h>
#include<conio.h>
main()
{
inta=0
clrscr()
while(a<255)
{
printf("%d=%c",a,a)
a++//incrementstatement
}
getch()
}

(e)WriteaprogramtoprintoutallArmstrongnumbersbetween1and500.Ifsumofcubesof
eachdigitofthenumberisequaltothenumberitself,thenthenumberiscalledan
Armstrongnumber.Forexample,153=(1*1*1)+(5*5*5)+(3*3*3)
#include<stdio.h>
#include<conio.h>
main()
{
inta,b,c,d,e,f,res,num=1
clrscr()
printf("ArmstrongNumbersfrom1to500\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)Writeaprogramforamatchstickgamebeingplayedbetweenthecomputerandauser.
Yourprogramshouldensurethatthecomputeralwayswins.Rulesforthegameareas
follows:?Thereare21matchsticks.?Thecomputeraskstheplayertopick1,2,3,or4
matchsticks.?Afterthepersonpicks,thecomputerdoesitspicking.?Whoeverisforcedto
pickupthelastmatchsticklosesthegame.
SubmittedbyRahulRaina
voidmain()
{
intx,y,n=21
clrscr()
printf("TheTotalAmountOfMatchsticksis21")
while(n>1)
{
printf("\nEnterYourChoice:")
scanf("%d",&x)
if((1<=x)&&(x<=4))
{
n=nx
printf("\nTheuserchose%d,thematchsticksleft%d",x,n)
}
else
{
printf("\nWrongEntry")
break
}
y=5x
n=ny
printf("\nThecomputerchose%d,thematchsticksleft%d",y,n)
}

http://letuscsolutions.weebly.com/chapter3.html

2/15

11/16/2015

Chapter3LetUsCSolutions
if(n==1)
printf("\nLastMatchStickLeft,YouLose")
getch()
}

(g)Writeaprogramtoenterthenumberstilltheuserwantsandattheenditshoulddisplay
thecountofpositive,negativeandzerosentered.
#include<stdio.h>
#include<conio.h>
main()
{
intnum,x,p=0,n=0,z=0
/*num=numberentered,x=Totalnumbersuserwanttoenter
p=positivenumbers,n=negativenumbers,z=zeros*/

clrscr()
printf("Howmanynumbersdoyouwanttoenter?")
scanf("%d",&x)
while(x>0)
{
scanf("%d",&num)
if(num>0)
p++
if(num<0)
n++
if(num==0)
z++
x
}
printf("\nYouEntered:\n%dPositiveNumbers\n%dNegativeNumbers\n%dZeros",p,n,z)
getch()
}

(h)Writeaprogramtofindtheoctalequivalentoftheenterednumber.
#include<stdio.h>
#include<conio.h>
main()
{
longinti,num,arr[100]//i=loopvariable,num=givennumber,arr[100]=array
clrscr()
printf("EnteranynumbertoconvertintoOctal:")
scanf("%ld",&num)
for(i=0num>8i++)
{
arr[i]=num%8
num=num/8
}
printf("OctalConversionis\n")
printf("%d",num)
while(i>0)
{
printf("%d",arr[i1])
i
}
getch()
}

(i)Writeaprogramtofindtherangeofasetofnumbers.Rangeisthedifferencebetweenthe
smallestandbiggestnumberinthelist.
ComingSoon...

[E]Attemptthefollowing:
(a)Writeaprogramtoprintallprimenumbersfrom1to300.
(Hint:Usenestedloops,breakandcontinue)
#include<stdio.h>
#include<conio.h>
main()
{
intnum,i,n=300//num=primenumbers,n=totalno.ofprimenumbers
clrscr()
for(num=1num<=300num++)
{
i=2
while(i<n1)
{
if(num%i==0)
break

http://letuscsolutions.weebly.com/chapter3.html

3/15

11/16/2015

Chapter3LetUsCSolutions
i++
}
if(i==num)
printf("%d",num)
}
getch()
}

(b)Writeaprogramtofilltheentirescreenwithasmilingface.
ThesmilingfacehasanASCIIvalue1.
#include<stdio.h>
#include<conio.h>
main()
{
intx=1,a=1
clrscr()
while(x<80*50)
{
printf("%c",a)
x++
}
getch()
}

(c)Writeaprogramtoaddfirstseventermsofthefollowingseriesusingaforloop:

#include<stdio.h>
#include<conio.h>
main()
{
longdoublenum,res,fres=0,fact=1.0
/*num=number,res=result,fres=finalresult,fact=factorial*/
clrscr()
for(num=1.0num<=7.0num++)
{
fact=fact*num
res=num/fact
fres=fres+res
}
printf("Thesumofgivenseriesis%.9Lf",fres)
getch()
}

(d)Writeaprogramtogenerateallcombinationsof1,2and3usingforloop.
#include<stdio.h>
#include<conio.h>
main()
{
inta,b,c
clrscr()
for(a=1a<=3a++)
{
for(b=1b<=3b++)
{
for(c=1c<=3c++)
{
if(a==b||b==c||a==c)
continue
else
printf("%d%d%d\n",a,b,c)
}
}
}
getch()
}

(e)Accordingtoastudy,theapproximatelevelofintelligenceofapersoncanbecalculated
usingthefollowingformula:
i=2+(y+0.5x)Writeaprogram,whichwillproduceatableofvaluesofi,yandx,wherey
variesfrom1to6,and,foreachvalueofy,xvariesfrom5.5to12.5instepsof0.5.
ComingSoon...

http://letuscsolutions.weebly.com/chapter3.html

4/15

11/16/2015

Chapter3LetUsCSolutions
(f)Writeaprogramtoproducethefollowingoutput:
ABCDEFGFEDCBA
ABCDEFFEDCBA
ABCDEEDCBA
ABCDDCBA
ABCCBA
ABBA
AA
#include<stdio.h>
#include<conio.h>
main()
{
inta,x,n=71,o=70,y=1,c
clrscr()
for(x=1x<=7x++)
{
for(a=65a<=na++)//loopforprintingABCDEFG
printf("%c",a)
if(x==2)
o=70
for(c=2c<yc++)//spaceloop
printf("")
for(a=oa>=65a)//loopforprintingFEDCBA
printf("%c",a)
printf("\n")//tosta
n
o
y=y+2
}
getch()
}

(g)Writeaprogramtofilltheentirescreenwithdiamondandheartalternatively.TheASCII
valueforheartis3andthatofdiamondis4.
#include<stdio.h>
#include<conio.h>
main()
{
inta,b,c,d
clrscr()
for(c=1c<=37c++)
{
for(d=1d<=49d++)
{
for(a=4a<=4a++)
{
for(b=3b<=3b++)
printf("%c%c",a,b)
}
}
}
getch()
}

(h)Writeaprogramtoprintthemultiplicationtableofthenumberenteredbytheuser.The
tableshouldgetdisplayedinthefollowingform.
29*1=29
29*2=58

#include<stdio.h>
#include<conio.h>
main()
{
intres,no,a=1//res=result,no=number,a=loopvariable
clrscr()
printf("Enteranynumbertoknowitstabletill12:")
scanf("%d",&no)
while(a<=12)
{
res=a*no
printf("%dX%d=%d\n",no,a,res)
a++
}

http://letuscsolutions.weebly.com/chapter3.html

5/15

11/16/2015

Chapter3LetUsCSolutions
getch()
}

(i)Writeaprogramtoproducethefollowingoutput:
1
23
456
78910
#include<stdio.h>
#include<conio.h>
main()
{
inta,b,n=6
clrscr()
for(a=1a<=10a++)
{
if(a==1||a==2||a==4||a==7)
{
printf("\n")
for(b=1b<=nb++)
printf("")
n=n2
}
printf("%4d",a)
}
getch()
}

(j)Writeaprogramtoproducethefollowingoutput:
1
11
121
1331
14641
#include<stdio.h>
#include<conio.h>
main()
{
intl,a=8,i=1,s,x,y=1
clrscr()
for(l=1l<=5l++)
{
for(s=1s<=as++)
printf("")
printf("%4d",i)
if(l>=3)
{
for(x=1x<=yx++)
{
if(x==2&&y==3)
printf("%4d",l+1)
else
printf("%4d",l1)
}
y++
}
if(l>=2)
printf("%4d",i)
a=a2
printf("\n")
}
getch()
}

(k)AmachineispurchasedwhichwillproduceearningofRs.1000peryearwhileitlasts.
ThemachinecostsRs.6000andwillhaveasalvageofRs.2000whenitiscondemned.If
12percentperannumcanbeearnedonalternateinvestmentswhatwouldbetheminimum
lifeofthemachinetomakeitamoreattractiveinvestmentcomparedtoalternative
investment?
ComingSoon...

http://letuscsolutions.weebly.com/chapter3.html

6/15

11/16/2015

Chapter3LetUsCSolutions
(l)Wheninterestcompoundsqtimesperyearatanannualrateofr%fornyears,the
principlepcompoundstoanamountaasperthefollowingformula

Writeaprogramtoread10setsofp,r,n&qandcalculatethecorrespondingas.
ComingSoon...

(m)Thenaturallogarithmcanbeapproximatedbythefollowingseries.

Ifxisinputthroughthekeyboard,writeaprogramtocalculatethesumoffirstseventerms
ofthisseries.
#include<stdio.h>
#include<conio.h>
main()
{
inta,b,x,y,z=1
floatres,r1=1
clrscr()
printf("Entervalueofx:")
scanf("%d",&x)
for(a=1a<=7a++)
{
for(y=1,r1=1y<=zy++)
{
r1=r1*(x1)/x
}
z++
if(a>=2)
res=res+(0.5*r1)
else
res=res+r1
}
printf("Sumoffirstseventermsofgivenseries:%f",res)
getch()
}
BacktoTop

46Comments

LetUsCSolutions

Share

Recommend 5

Login

SortbyBest

Jointhediscussion
sowjanya 3yearsago

sirgivethesolutionsofremainingsectionsalso...orelsetellwhereIcanfind
solutions
22

Reply Share

PratapSingh 3yearsago

PleaseaddmorechaptersASAP
6

Reply Share

AmarKaldate 2yearsago

Thenaturallogarithmcanbeapproximatedbythefollowingseries.
((21)/2)+0.5((21)/2)^2+0.5((21)/2)^3+0.5((21)/2)^4+....
Ifxisinputthroughthekeyboard,writeaprogramtocalculatethesumoffirst
seventermsofthisseries.

http://letuscsolutions.weebly.com/chapter3.html

#include<stdio.h>
voidmain()
{
inti,j
floatx,a,y,sum=0
printf("PleaseEnterTheValueofX\t")
scanf("%f",&x)
i=1

7/15

11/16/2015

Chapter3LetUsCSolutions
i=1
y=(x1)/x
while(i<=7)
{
if(i>1)
{
seemore

Reply Share

A 2yearsago

[E]e.Accordingtoastudy,theapproximatelevelofintelligenceofapersoncan
becalculatedusingthefollowingformula:
i=2+(y+0.5x)
Writeaprogram,whichwillproduceatableofvaluesofi,yandx,wherey
variesfrom1to6,and,foreachvalueofy,xvariesfrom5.5to12.5instepsof
0.5.
Ans:
#include<stdio.h>
intmain(intargc,char*argv[])
{
floatx,y,i
for(y=1y<7y++)
{printf("valueofyis%f\n",y)
for(x=5.5x<=12.5x=x+.5)
{i=2+(y+.5*x)
printf("%f\t%f\n",x,i)
}
printf("\n\n")
}
return0
}
2

Reply Share

AmarKaldate 2yearsago

#include<stdio.h>
voidmain()
{
intn,max,min,flag=1
charch='y'
while(ch=='y')
{
printf("PleaseEnterTheno.\t")
scanf("%d",&n)
while(flag==1)
{
max=n
min=n
flag=0
}
if(max>=n)
max=max
seemore

Reply Share

AmarKaldate>AmarKaldate 2yearsago

AbovecodeisforWriteaprogramtofindtherangeofasetofnumbers.
Rangeisthedifferencebetweenthesmallestandbiggestnumberinthe
list.
1

Reply Share

sagarjyotisenapati>AmarKaldate amonthago

Sonyc.

Reply Share

AmarKaldate 2yearsago

http://letuscsolutions.weebly.com/chapter3.html

Q(l):Wheninterestcompoundsqtimesperyearatanannualrateofr%forn

8/15

11/16/2015

Chapter3LetUsCSolutions
Q(l):Wheninterestcompoundsqtimesperyearatanannualrateofr%forn
years,theprinciplepcompoundstoanamountaasperthefollowingformula:
a=p(1+r/q)^np
Writeaprogramtoread10setsofp,r,n&qandcalculatethecorresponding
as
#include<stdio.h>
voidmain()
{
intx,i,n,p,q
floata,r,y,j
i=1
while(i<=10)
seemore

Reply Share

2yearsago

Writeaprogramtosumfirst10termsofthefollowingseriesy=x+x3/2+x5/3+
takevalueofxasinputandprintthevalueofy.pleaseineedit'ssolution
1

Reply Share

jigsaww 2yearsago

Greatjobbuttherearesomeanswerswhichcanbeshortenedandmade
simpler.GREATJOB!:)
1

Reply Share

priyeshwardubey 2yearsago

goodprogram
1

Reply Share

Humza 3yearsago

forotherprogramsyouhavetwopayfees,
hainnairtiqaji
1

Reply Share

Humza 3yearsago

HHmmmm/............./ProfessorIrtiqaismakingprograms

Reply Share

Ahsan>Humza 3yearsago

KindlyAddmoreProgramsifyoucansothatmoreandmorepeoplecan
getbenefitfromit.IpersonallyLearntalot.Thanks
1

Reply Share

megha ayearago

//B(PARTI)programtofindrange
#include<stdio.h>
#include<conio.h>
voidmain()

http://letuscsolutions.weebly.com/chapter3.html

{intmax=0,min=0,n,a[20],i
printf("enterhowmuchnumbersuwant")
scanf("%d",&n)
printf("entertheno")
for(i=0i<ni++)scanf("%d",&a[i])=""max="a[0]"for(i="0i&ltni++)"{=""
if(max<a[i])=""max="a[i]"}printf("max=""is\n%d",max)=""min="a[0]"
for(i="0i&ltni++)"{=""if(min="">a[i])
min=a[i]
}printf("minis\n%d",min)
printf("rangeis%d\n",maxmin)
getch()
}

9/15

11/16/2015

Chapter3LetUsCSolutions
}
1

Reply Share

sagarjyotisenapati>megha amonthago

Nyc

Reply Share

AkhtarKhan amonthago

thankyousir

Reply Share

ShantanuPathak 4monthsago

Questionno:E
#include<stdio.h>
voidmain()
{
floati,y,x
printf("APPROXIMATIONOFINTELLIGENCE")
printf("\n")
printf("\n")
for(y=1y<=6y++)
{
for(x=5.5x<=12.5x=x+0.5)
seemore

Reply Share

PankajNaik 4monthsago

#include<stdio.h>
main()
{
inty
floati,x
printf("___________________________________\n\n")
printf("\ty\tx\ti\n")
printf("___________________________________")
for(y=1y<=6y++)
{
for(x=5.5x<=12.5x=x+0.5)
seemore

Reply Share

Siraj 5monthsago

AnswerofQuestionE(e).
#include<stdio.h>
#include<conio.h>
voidmain()
{
floatx,y
for(y=1y<=6y++)
{

http://letuscsolutions.weebly.com/chapter3.html

10/15

11/16/2015

Chapter3LetUsCSolutions
for(x=5.5x<=12.5x=x+0.5)
{
printf("\ni=%f",2+(y+(0.5*x)))
}
}
getch()
}

Reply Share

naveedchauhan 8monthsago

Q1:WriteaprogramtocheckifanumberinputbyuserisPRIMEornot,range
ofinputis1to300.

Reply Share

tejaswini 9monthsago

1
22
333
4444
55555
Tsisisoutputplzgivemeansanyone

Reply Share

DhimanMridha 2yearsago

Problem[E](f)canalsobesolvedlikethis.
Lotmoreeasier.:)
#include<stdio.h>
main()
{
inta=1
printf("\n")
for(aa<2a++)
{
printf("ABCDEFGFEDCBA")
}printf("\n")
seemore

Reply Share

Dhiman>DhimanMridha 2yearsago

Whythespacebetweenthecodedoesnotshow:(

Reply Share

DhimanMridha 2yearsago

Problem[E](f)canalsobesolvedlikethis.
It'slotmoreeasier,trythis.
#include<stdio.h>
main()
{
inta=1
printf("\n")
for(aa<2a++)
{

http://letuscsolutions.weebly.com/chapter3.html

11/15

11/16/2015

Chapter3LetUsCSolutions
printf("ABCDEFGFEDCBA")
}printf("\n")
seemore

Reply Share

DhimanMridha 2yearsago

Problem[E](a)canalsobesolvedbythis.
Iusedtwointegerinstedthreeasadmindid.
#include<stdio.h>
main()
{
inta,b
printf("Alltheprimenumbersbetween1to300aregivenbelow:\n")
for(a=1a<=300a++)
{
b=2
while(b<=a1)
seemore

Reply Share

DhimanMridha 2yearsago

Thereisamistakein[E](a)
insidewhileitmustbe(i<=n1)
Adminhasgiven(i<n1)so,=""when=""the=""number=""is=""3=""the=""
compiler=""can=""not=""judge=""wheter=""it=""is=""prime=""number=""
or=""not.="">

Reply Share

RohanKhan 2yearsago

another1forprintingalphabetsorder:
#include<stdio.h>
#include<conio.h>
main()
{
inty,sp
chara,x
a=71/*ASCIIvalueofGstoredina*/
for(y=1y<=7y++)/*primarytestisindependentofa*/
{
for(x=65x<=ax++)/*forprintingABCD...inincreasingorder*/
seemore

Reply Share

chetanraikwar 2yearsago

solutionstoletusC.http://letuscalllessons.blogsp...

Reply Share

yusrarehan 2yearsago

plzhelpmetounderstandtheseprograms.......


http://letuscsolutions.weebly.com/chapter3.html

Reply Share

12/15

11/16/2015

Chapter3LetUsCSolutions
Guest 2yearsago

#include<iostream.h>
voidmain()
{
ints=6
for(inta=1a<=10a++)
{
if(a==1||a==2||a==4||a==7)
{
cout<<endl<<endlfor(int=""b="1b&ltsb++)"{=""cout<<"="""=""}=""}=""
s="s1"cout<<a<<"="""=""}=""}="">

Reply Share

Guest 2yearsago

Chapter3[E](i)
(i)Writeaprogramtoproducethefollowingoutput:
1
23
456
78910
#include<iostream.h>
voidmain()
{
ints=6
for(inta=1a<=10a++)
{
if(a==1||a==2||a==4||a==7)
{
cout<<endl<<endlfor(int=""b="1b&ltsb++)"{=""cout<<"="""=""}=""}=""
s="s1"cout<<a<<"="""=""}=""}="">

Reply Share

noorfatima 2yearsago

kindlygivethesolutionsofremainingquestionsortellmewhereicanfindthese
solutions

Reply Share

Asad.ur.Rehman 2yearsago

MOstlyprogramesareincorrect.....pleaseusecorrectlycodeforGODsays..
pleasepleaseifnotthenturnoffthiswebsitethanks..
whydropthefutureofyoungestwithyourwrongcode?
whyyoudestringthefutureofyoungestbythiswrongprogramming....?
Allprogrammesincludesmosterrors...
pleaseusecorrectcodingThanks.......

Reply Share

utkarsh 2yearsago

inques[B]h.)
thecondtioninforloopwillbe..
for(i=0num!=0i++)
not
for(i=0num>0i++)

Reply Share

ali 2yearsago

ididn'tgettheideaofquestion(i)

Reply Share

Gayathri 2yearsago

THANKSALOT

Reply Share

robin 2yearsago

veryhelpfullprograms...........


http://letuscsolutions.weebly.com/chapter3.html

Reply Share

13/15

11/16/2015

Chapter3LetUsCSolutions
muhammadusman 2yearsago

thnkzzzzz!!!allprgrmareamazing!!!andveryhelpfull:P:P:P

Reply Share

ali 3yearsago

isE(F)working?

Reply Share

TAYYAB 3yearsago

niceprograms.....ieasilyunderstandit....thankstoprofessorwhomadeit...

Reply Share

PriyaPatidar 3yearsago

Tothisprogramsthanksandpleasaddmorechapter

Reply Share

mysteriouszem 3yearsago

greatjobthanks

Reply Share

ShakerShafi 8monthsago

qustion(i)
#include<stdio.h>
voidp_factor(int)
voidmain()
{
intno,factor
printf("PleaseEnterTheno\t")
scanf("%d",&no)
p_factor(no)
}
voidp_factor(inta)
{
inti=2,j=a
while(i<=j)
{
if(j%i==0)
{
j=j/i
printf("%d",i)
}
else
i++
}
}

Reply Share

jonesjude>ShakerShafi 8monthsago

Weusehighqualityequipmentandmaterialstoproduceourcounterfeit
documentsbutwedorealdocumentsaswell.Allsecretfeaturesofreal
passportsarecarefullyduplicatedforourfalsifieddocumentsbutreal
documentsarebackedinthedatabasemeaningtheycanberenewed
legally.WeofferoriginalhighqualityfakeandoriginalPassports,
DiplomaticPassports,Driver'sLicenses,IDcards,Stamps,Visas,
SchoolDiplomase.t.c.Foranumberofcountrieslike:
USA(UnitedStates),Australia,Canada,UK(UnitedKingdom),
Germany,Belgium,France,Brazil,Finland,Netherlands,Israel,Spain,
Italy,Mexico,SouthAfrica,Austria,Bahrain,Argentina,India,China,
HongKongandanyothercountrythatyourequire.
soifinterested,getbacktousformoreinformation

Reply Share

SALMANALI 3yearsago

veryinterestingsolutions....thankstheuploader!!

http://letuscsolutions.weebly.com/chapter3.html

Reply Share

14/15

11/16/2015

Chapter3LetUsCSolutions

http://letuscsolutions.weebly.com/chapter3.html

Subscribe

AddDisqustoyoursite

Privacy

15/15

Anda mungkin juga menyukai