473,480 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

is the output correct

29 New Member
int n = 20;

while(n>0)
n/=2;
std::cout<<n * n<<std::endl;


is this correct if i divide 20/2 = 10
and multiply 10*10 as the output
Jun 12 '07 #1
1 1037
Extremist
94 New Member
The output of your code will be 0;
The while will continue until n = 0;

n = 20 while makes n = 10
n = 10 while makes n = 5
n = 5 while makes n = 2
n = 2 while makes n = 1
n = 1 while makes n = 0

perhaps what you mean to do is:

Expand|Select|Wrap|Line Numbers
  1. int n = 20;
  2.     while(n>0)
  3.     {
  4.         n/=2;    
  5.         std::cout <<n*n<< std::endl;
  6.     }
  7.  
Output will be
100
25
4
1
0
Jun 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3774
by: Robert | last post by:
Hello, I am trying to get output formatted from a non-php script that I post to. Example: <form method=POST action=www.myurl.com/ColdFusion.cfm> bla bla bla </form>
3
4923
by: Beowulf | last post by:
Hi, I have an XML file generated by a third party (and therefore unchangable) program. 1st line in it is <?xml version="1.0" encoding="us-ascii"?> and down in the depths of the xml I have a...
5
2151
by: Tom Lam lemontea | last post by:
Hi all, This is my very first post here, I've seriously tried some programming on C, and shown below is my very first program(So you can expect it to be very messy) that I wrote after I've learned...
8
2663
by: Alec MacLean | last post by:
Hi, I'm using the DAAB Ent Lib (Jan 2006) for .NET 2.0, with VS 2005 Pro. My project is a Web app project (using the WAP add in). Background: I'm creating a survey system for our company, for...
3
1599
by: wuzertheloser | last post by:
The correct program should look like this: Total number of voting cards: 55 Votes for candidate 1: 1 Votes for candidate 2: 10 Votes for candidate 3: 8 Votes for candidate 4: 13 Votes...
6
1866
by: Rafael Olarte | last post by:
The goal of this project is to output the following information as follows: 34.5 38.6 4.1 42.4 3.8 close 46.8 4.4 big change. The values of the first colunm are obtain from a file...
3
6079
by: John Williams | last post by:
I'm writing a stagenography program to experiment with how it works. The algorithm I'm using appears to be producing the correct result...however I'm struggling with the file input. I never...
19
33259
by: Dancefire | last post by:
Hi, everyone It might be a simple question, but I really don't know the answer. char c = '1'; cout << c; The above code will only output a '1' rather than 0x31; If I use int cast, it can...
2
1612
by: Oli Thissen | last post by:
Hello everybody! I'm having a little problem with the following: I wrote a class to collect data (Let's call it DataCollector). Now I want the data to be interpreted in various ways. My idea was...
0
1787
by: jebbyleezer | last post by:
Hello, I have source code that builds correctly, however, after the program terminates the output file produced is empty. Here is my source code: import java.io.*; import java.util.Scanner;...
0
6911
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7050
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7091
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6743
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6966
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2999
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.