Search This Blog

Friday, 9 November 2012

How to generate Numbers automatically within a specific Range?

Lets say we want to print Numbers between 4 and 6, including 4 and 6.

#include<iostream>
using namespace std;
int main()

{
int x;
for ( x = 1 ; x <= 70 ; x++ ) // you can replace 70 with Any Number.
cout<< 4+   rand() % 3 <<endl; // to Produce Numbers between 4 & 6 including 4 and 6.

cout<<endl<<endl;
return 0;
}


Mod of 3 with any random number will give value less than 3 and greater than 0, and by adding any number from 0 to 2 with 4, we get either 4,5 or 6.

Simple!
C++: How to detect that user Pressed P button from keyboard? - Yahoo! Answers #include<iostream>
using namespace std;
int main()

{
int x;
for ( x = 1 ; x <= 70 ; x++ ) // you can replace 70 with Any Number.
cout<< 4+   rand() % 3 <<endl; // to Produce Numbers between 4 & 6 including 4 and 6.

cout<<endl<<endl;
return 0;
}


Mod of 3 with any random number will give value less than 3 and greater than 0, and by adding any number from 0 to 2 with 4, we get either 4,5 or 6.

Simple!

14 comments:

  1. hi
    sir can you explain these questions of
    function
    Question 1:
    Write a function which receives a float and an int from main( ), finds the product of these two and returns the product which is printed through main( ).

    Question 2:
    Write a function that receives 5 integers and returns the sum and average of these numbers. Call this function from main( ) and print the results in main().

    Question 3:
    A 5-digit positive integer is entered through the keyboard, write a function to calculate sum of digits of the 5-digit number.

    Question 4:
    A positive integer is entered through the keyboard, write a program to obtain the prime factors of the number.

    Question 5:
    Given N and K write a function to compute the Binomial Coefficient. Pass the value of N and K to the function, calculating Binomial.
    [Hint]: Make an additional function of factorial as well. Your main will contain only a single function call.

    N!

    K! (N-K)!
    Question 6:
    Write a function with the name mypower that behaves exactly like pow function of math.h and a function factorial

    Question 7:
    Write a function that receives as input three integer arguments and then circularly shift their values to right. (The change in variables must be permanent) Example:
    If x=5, y=8, z=10 then after circular shift y=5, z=8, and x=10.



    Question 8:
    Write a function to find the binary equivalent of a given decimal integer and display it.

    Question 9:
    Write a function to obtain the first 25 numbers of a Fibonacci sequence. In a Fibonacci sequence the sum of two successive terms gives the third term. Following are the first few terms of the Fibonacci sequence: 1 1 2 3 5 8 13 21 34 55 89...
    Question 10:
    Write a C++ function to evaluate the series

    ReplyDelete
  2. Hello Abdullah Jahangir,
    We appreciate your thirst for learning, I'll include all the Questions mentioned, with a brief introduction of Functions.

    Feel free to ask anything!

    Take Care.

    ReplyDelete
  3. Goto 'Library of Solved Programs' tab from my website.

    ReplyDelete
  4. thanks alot
    its a wonderful website
    i really love it
    it's very helpful

    ReplyDelete
  5. I go to see еach ԁaу ѕome blogs and sіteѕ to rеad posts,
    but thіs web site ρrovides feаture baseԁ writing.


    Feel free tο visit my homepаge .
    .. This Web-site

    ReplyDelete
  6. It's great that you are getting ideas from this post as well as from our argument made here.

    Also visit my site - verdopple deine dates

    ReplyDelete
  7. Thаnkѕ for fіnally writing about > "How to generate Numbers automatically within a specific Range?" < Liked it!

    My webpage H�morrhοidеn

    ReplyDelete
  8. I've been exploring for a bit for any high-quality articles or blog posts in this kind of space . Exploring in Yahoo I at last stumbled upon this site. Reading this information So i am happy to exhibit that I've a very
    good uncаnny feeling I саme upon exactlу what Ι
    neеded. Ӏ suсh a lot surely wіll make certain
    to dοn?t forget thіs websitе and giѵe it a
    glаnce regularlу.

    my page - Acne Problem

    ReplyDelete
  9. These агe rеаlly enоrmоus
    iԁeаs in гegarding blogging.
    You have touched ѕomе pleasant factors here.

    Any way keep up wrinting.

    Have a look at my ωeb-site :: home cure for hemorrhoids

    ReplyDelete
  10. I thіnk that is among the most imрortant information for me.
    And і'm satisfied studying your article. But wanna remark on few normal things, The website taste is perfect, the articles is in reality excellent : D. Good job, cheers

    Feel free to surf to my homepage - häMorrhoiden Bilder

    ReplyDelete
  11. Good dаy! Do you know if theу make any plugins to safеguard against hacκeгs?

    I'm kinda paranoid about losing everything I'νe worked haгd on.

    Αny recοmmendаtions?

    My blog :: hemorroides

    ReplyDelete
  12. I'd like to find out more? I'd caгe to finԁ out some additional
    infοгmation.

    Revіew my web-site ... weight gain

    ReplyDelete
  13. Hi! This is my 1st cοmmеnt hеre ѕo I just wanted to gіve a quick shout out and tell you I genuinely enϳoy геading your posts.
    Сan you rесommеnd аny other blοgs/websites/forums that deal with the same subjects?
    Thankѕ a ton!

    my websitе; acne Treatment

    ReplyDelete
  14. Have yοu еver considereԁ crеating аn ebook or gueѕt authoring on
    other wеbsiteѕ? I haѵе a blοg centerеԁ οn thе sаme
    information you disсuѕs and would really lіke to haνe you
    sharе ѕomе stοries/infoгmation.
    I knоw my reаԁers ωoulԁ enjoy your
    work. If you're even remotely interested, feel free to shoot me an e-mail.

    Here is my webpage: best cure for premature ejaculation

    ReplyDelete