TechTalkz.com Logo Ask the Expert

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > TechTalkz Member Reviews & Guides > Guides

Notices

C++ Guide: Part 2

Guides


Comment
 
Article Tools Display Modes
<!-- google_ad_section_start -->C++ Guide: Part 2<!-- google_ad_section_end -->
C++ Guide: Part 2
Published by Dark Star
20-10-2006
Smile Do-While Loop


DO WHILE STATEMENT

The do while loop is the 2'nd type of loop, the main positive aspect of thios loop that whether the condition is true or false the loop will run one time, if the condition will be true then the loop will be continued otherwise it will stop..
The syntax of the do while statement is as follows:-
Code:
do
{
<program statement>
}
while(<condition>);
Here the condition is at the last so the loop will run 1'st time till reaching the condition....
The followind point should be remembered while using do-while loop:---
  1. (1)It is executed at least once..
  2. (1)It is executed till the condition remains trueand the control comes out as soon as the loop ends.
  3. (1)There must be some looping terminating condition otherwise the loop willnot stop...
Here are some e.g. To clear ur doubts........
  • To check whether the number is Armstrong or not....
Note:- An armstrong no. Is a no. Whose digit cube sum is equal to the same no..
Code:
void main()
{
clrscr();
int n,k,r.s;
cout<<"Enter the number\n";
cin>>n;
k=n;
s=0;
do
{
r=n%10;
s=s+r*r*r;
n=n/10;
}while(n!=0);
if(k==s)
cout<<"It is Armstrong no.";
else
cout<<"It is not Armstrong No..";
getch();
}

In the above program I had taken 4 variables n for storing the number, k for storing the value of n so that we can check the condition,s for adding,r for taking remainder or storing every digit of the entered number...
So suppose u had entered the no 153 the no. Gets stored in k so n and k both will hold 153. Now the loop will begins first acc/cond given no will get divided be 10 and the remainder will get stored in r. First when u will divide 153 by 10 the remainder will come 3 the in second line cube of 3 i.e 27 will be added to s i.e 0 so s is now 27 then the remaining part will again got divided and the cube of 5 i.e 125 then again the last no cube i.e 1 will be added so the sum of 27+125+1=153 so the no. Is armstrong no..
  • To find factorial of any number.
Code:
void main()
{
clrscr();
int n,f;
cout<<"Enter the number\n";
cin>>n;
f=1;
do
{
f=f*n;
n=n-1;
}while(n!=0);
getch();
}
I have already explained it so its should be clear to all...
Published by
Dark Star's Avatar
Elite Member (1000+)
Join Date: May 2006
Location: /dev/had0
Age: 20
Posts: 1,627
Rep Power: 45
Dark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just Great

Contents

Article Tools

Latest 5 articles

Featured Articles
<<  <    Next Page: For Loop (Page 5 of 6)    >  >>
Old 22-10-2006, 12:37 PM   #1
Senior Member (500+)
 
Join Date: Jun 2006
Location: Mumbai.
Age: 17
Posts: 505
Thanks: 6
Thanked 27 Times in 22 Posts
Rep Power: 18 Sam RuleZ has much to be proud ofSam RuleZ has much to be proud ofSam RuleZ has much to be proud ofSam RuleZ has much to be proud ofSam RuleZ has much to be proud ofSam RuleZ has much to be proud ofSam RuleZ has much to be proud ofSam RuleZ has much to be proud of
Send a message via Yahoo to Sam RuleZ
Nice guide !
__________________
"Its better to get burnt, than to fade away"-Kurt Cobain.

Sam RuleZ is offline   Reply With Quote
Old 22-10-2006, 01:45 PM   #2
ƒ(ψ)=ΘΊΧφ
 
bakuryu's Avatar
 
Join Date: May 2006
Location: India
Age: 24
Posts: 6,621
Thanks: 19
Thanked 649 Times in 605 Posts
Rep Power: 87 bakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant future


OS: Windows XP Windows Vista Windows 7


Send a message via Yahoo to bakuryu
Quote:
i+1=i;
doesn't make any sense ..... and is logically incorrect.

a = i++;
// means :
// a = i;
// i = i + 1;

and a = ++i;
//means
// i = i + 1; (and not i+1 = i)
// a = i;


Quote:
  1. (1)The loop will not get executed if the given condition becomes false.
or if the expression is numerically 0. Any number other than 0 is considered TRUE, 0 is considered FALSE

Quote:
(1)The loop will be executed till the condition is false the result will be presented as soon as the condition becomes false.
Only if there's no break statement inside the loop. And the control comes out of the loop when the condition evaluates to FALSE, rather than "result will be presented as soon as the condition becomes false."
__________________
Please don't click here

Last edited by bakuryu; 22-10-2006 at 01:50 PM..
bakuryu is offline   Reply With Quote
Old 22-10-2006, 07:44 PM   #3
Junior Member (25+)
 
Join Date: Sep 2006
Age: 24
Posts: 64
Thanks: 7
Thanked 5 Times in 5 Posts
Rep Power: 3 luvrohit85 will become famous soon enough
hello

from where do u get this c++ guide book online can please tell me the website so that i can download it..
__________________
.RoHiTkUmAr.
luvrohit85 is offline   Reply With Quote
Old 22-10-2006, 09:56 PM   #4
Elite Member (1000+)
 
Dark Star's Avatar
 
Join Date: May 2006
Location: /dev/had0
Age: 20
Posts: 1,627
Thanks: 98
Thanked 172 Times in 146 Posts
Rep Power: 45 Dark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just Great


OS: Linux


Hey I had made it by my own beleive me
Dark Star is offline   Reply With Quote
Old 30-10-2006, 07:13 PM   #5
Founder
 
Strider's Avatar
 
Join Date: Nov 2005
Location: The Last City Zion!
Posts: 3,876
Thanks: 371
Thanked 411 Times in 356 Posts
Rep Power: 67 Strider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just Great


OS: Windows XP Windows Server 2003 / Windows Server 2008 Windows Vista Windows 7 Linux


Keep it up shah.. Good work.. Kepp them coming
Strider is offline   Reply With Quote
Comment

Article Tools
Display Modes


Similar Threads
Article Article Starter Category Comments Last Post
IE7 Cache, Part 2 BruceD Internet Explorer 2 28-08-2007 08:06 PM
IE7 Cache, Part 2 BruceD Internet Explorer 0 28-08-2007 07:57 PM
Re: I am Amazed - Part 33 1/3 MarkyMarc43 Windows Vista All 1 17-08-2007 07:34 PM
I am amazed part 2.... Tiberius Windows Vista All 9 17-08-2007 07:32 PM
Re: I am Amazed - Part 33 1/3 Homer Schwartz Windows Vista All 0 17-08-2007 07:21 PM


< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 05:11 AM.


vBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2010, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional