473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Positive Integer

Can anybody help me with writing this program?
I do not know what function to use?

1. Prompt the user for a positive integer.
2. Print the numbers from zero to that number in the web page, each number on a separate line.

Thanks
Oct 25 '07 #1
3 2809
acoder
16,027 Expert Mod 8TB
Can you show the code that you have so far.

For the first question, you would normally use the prompt() method.

Use a for loop for the second question: for loop.
Oct 26 '07 #2
Thanks:
Here is my code. I want to enter a positive number and print out from zero to that number.
[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD><SCRIPT language="JavaScript" type="text/javascript">
var i= prompt('Please enter a positive integer:', ' ');
</script>
<TITLE>CSL1</TITLE>
<META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ 2004">
</HEAD>

<BODY><h3>I should be able to enter 10000 and it should
print 1,2,3,....10000<P>


1.Prompt the user for a positive integer.<P>
2.Print the numbers from <U>zero to that number</U> in the web page, each number on a separate line.<P>
3.You do not have to do data validation. You can assume the user will actually give you a positive integer.<P>
You do not have to worry about over writing the page with your results.<P></h3>[/html]
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. for (i = 0; i <1000; i++)
  3. {
  4. document.write(i)
  5. document.write("<br />")
  6. }
  7. </script><P>
  8.  
  9.  
  10.  
  11. <SCRIPT language="JavaScript" type="text/javascript"> 
  12. > //var x= prompt('Please enter a positive integer:', ' '); 
  13. > </script> 
  14. > <TITLE>CSL</TITLE> 
  15. >
  16. > <SCRIPT language="JavaScript" type="text/javascript"> 
  17. > /*if (x ==0)  
  18. > {    
  19. > document.write(0+ ' <BR> ');  
  20. >   
  21. > } 
  22. > else if (x ==2)  
  23. > {    
  24. > document.write(0+ ' <BR> ' + 2 + '<BR> ');  
  25. >   
  26. > } 
  27. > else if (x ==4)  
  28. > {    
  29. > document.write(0+ ' <BR> ' + 2 + '<BR> ' + 4  + '<BR>');  
  30. >   
  31. > } 
  32. > else if (x ==6)  
  33. > {    
  34. > document.write(0+ ' <BR> ' + 2 + '<BR> ' + 4  + '<BR>' + 6 +
  35. > '<BR>');  
  36. >   
  37. > } 
  38. > else if (x ==8)  
  39. > {    
  40. > document.write(0+ ' <BR> ' + 2 + '<BR> ' + 4  + '<BR>' + 6 +
  41. > '<BR>' + 8 + '<BR>');  
  42. >   
  43. > } 
  44. > else if (x ==10)  
  45. > {    
  46. > document.write(0+ ' <BR> ' + 2 + '<BR> ' + 4  + '<BR>' + 6 +
  47. > '<BR>' + 8 + '<BR>' + 10 + '<BR>');  
  48. >   
  49. > } 
Expand|Select|Wrap|Line Numbers
  1. </script> 
  2. > </BODY> 
  3. > </HTML>
  4.  
  5.  
  6.  
  7. </BODY>
  8. </HTML>
Oct 30 '07 #3
acoder
16,027 Expert Mod 8TB
Use a unique variable name for the prompt, e.g. num.

Then in your for loop, replace the 1000 with this num variable so that it loops to the positive integer and not just 1000.
Oct 31 '07 #4

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

Similar topics

7
by: NotGiven | last post by:
I need to check the $_GET to make certain it is a positive integer. is_integer($_GET) is not working. I think it thinks it's a sting. So I tried casting it to an int using,...
19
by: Harshan | last post by:
The range of signed int is - 2^15 to + (2^15 )-1 (-32768 to 32767) Why the one less at positive Range ? (compared to the negative side..!) I came to know that it uses 2's compliment...
11
by: gouqizi.lvcha | last post by:
Hi, All: I wonder what is the smallest positive double numbers in C in 32 bit CPU? Rick
6
by: shaveta | last post by:
pls help me to write a program such that we input an integer x,where x>0. For x, the program has to convert it into the sum of consecutive positive integers. for e.g. let x=10 output should be "10=...
19
by: Johs | last post by:
I need to make some special action if 'a' and 'b' are both positive or both negative. Is there some inbuilt function to check this? Johs
3
by: haelly | last post by:
Write a program that prompts the user to enter three different integer values.If the values are not different, the program prints a message"equal values" and terminates(hint: use the return...
1
by: haelly | last post by:
write a program that prompts the user to enter three different positive integer values.If the values are not different, the program prints a message"equal value" and terminates(hint:use the return...
7
by: kepano | last post by:
pls help me to write a program (in c) such that we input an integer x,where x>0. For x, the program has to convert it into the sum of positive integers (all posible!). for e.g. x =8 1. 8 2....
63
by: deepak | last post by:
Hi, Can someone give the standard function which can create positive integer value in C? Thanks, Deepak
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.