some simple questions

Pages: 12
hello every one

i have some questions here :)

1- see this pic http://img571.imageshack.us/img571/3935/70196195.jpg

can anybody explain to me how to do this? because i don't know even to start

***

2- i want to find sin(x)

and this is my code but it's not working,can you show me why?

1
2
3
4
double param,result;
  cin >> param;
  result = sin(param);
 cout << result;


*****

3- how to find a factorial for a number

e.g. input 5 = 5x4x3x2x1 so the is output 120, now please see my code

1
2
3
4
5
6
7
8
int count = 0;
int num;
int fact = num;
cout <<"Please enter a number:";
cin >> num;
for(int i = 2; i < num; i++)
   fact *= i;
cout <<",The factorial is " << fact;


*****

4- display all the prime numbers below a given number.

e.g. Given 23 then the result should be2 3 5 7 11 13 17 19

and this is my code but my problem is in the output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int num,isprime;
  cout <<"Please enter a number: ";
  cin >> num;
  for(int i=2; i<=num;i++)
  {
     isprime  = 1;
     for(int j=2; j<=i ; j++)
     {
        if( i == j)
           continue;
        else if( i % j == 0){
        isprime = 0;
     }
     if(isprime)
     cout<<i<<" ";
  }
}


****

please notice that i'm beginer so if there is any help please let it in a simple way because i want to understand

waiting for you guys :)
1. I have no idea. Does this have anything to do with programing?

2. That should work. What is the problem?

3. fact = num goes before you set the value of num. Move line 3 after line 5.

4. You've messed up your { and }. The one on line 16 should really be after line 13.
About (1) and (2):

Don't forget to #include <cmath> . You can find a bunch of useful functions there.

http://cplusplus.com/reference/clibrary/cmath/

1. If I'm not mistaken, That's the Taylor polynomial of order 6 of ln(x+1) around x0=0. Do you want to know how to evaluate it, or how to compute it from a given function?

EDIT: By the way, that equality is false. Taylor polynomials are only approximations of functions.
Last edited on
What's the problem with 1)?
You apparently already know what loops are, so that shouldn't be a problem. You can calculate a power using pow, if that's what you're having problems with.
Last edited on
hi hamsterman (514)

for Q2 the problem is the output is wrong

for Q3 thaaaanks it works now

for Q4 thanks again bro it's working now

really help me :)
Last edited on
m4ster r0shi (659)

yes i ues math lybrary hehe

thnks for your reply :)

****

helios (7023)
Athar (264)

firstly, thanks for your reply

i'm really poor in math, and i don't what should i do thats why i cant start with this programme

waiting for you :)
if i input 23 it will shows 23 seven times!
???
From the code you've posted, that should never happen.
helios (7024)

welcome back

yes i was msitaken sorry i confused hehe

now i edit my reply and there is the edition again

"for Q2 the problem is the output is wrong"
For Q2, mind that you are expected to give the input in radians, not in degrees. Maybe that's what causing the trouble. And what do you mean by "wrong"? What do you give and what do you get?

EDIT: Oh, I just saw that...
if i input 23 it will shows 23 seven times!
Last edited on
welcome m4ster r0shi (660)

for example if i input '10' so the result should be = 0.173648

because sin(10) = 0.173648

but the result in the programe is -.544
Ok. It's what I said then.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <cmath>
using namespace std;

double deg_to_rad(double deg)
{
    return (3.14159*deg)/180;
}

int main()
{
    cout << sin(10) << endl;
    cout << sin(deg_to_rad(10)) << endl;

    cout << "\nhit enter to quit...";
    cin.get();
}

EDIT: Check this out:

http://www.teacherschoice.com.au/maths_library/angles/angles.htm
Last edited on
1
2
3
4
double param,result;
  cin >> param;
  result = sin(3.14159265*param/180);
  cout << result;


thanks thats my code and it's work fine :)

what about Q1, i really don't know anything about it :(
empror9 wrote:
what about Q1
helios wrote:
1. That's the Taylor polynomial of order 6 of ln(x+1) around x0=0. Do you want to know how to evaluate it, or how to compute [a Taylor polynomial] from a given function?
Last edited on
opps, sorry

the question on a paper says:

"7) The expansion of ln(1 + x) is given in the following formula:

http://img571.imageshack.us/img571/3935/70196195.jpg

solve this formula"

so thats mean to compute it, am i right?
Honestly, I have no idea what it means. "Solve" is usually understood as meaning "find the value of x that makes this relationship true", but that value is already known; x=0, otherwise the numerators couldn't possibly be xn. The question makes no sense.
Maybe it means "solve for a given value of x", which would mean write a function taking x as a parameter and calculating the series. But it is really not very cleat at all.
i see, i will try to ask the lecturer first to understand

thanks everyone for helping me
here is the last Q for today,please help me to understand the question

"5) A salesperson gets 5% percent commission on sales less than RM1000, 8% percent on sales in the range RM1000 through RM2000, and 10% percent on sales in excess of RM2000. Design a flowchart that reads an arbitrary number of sales made by a salesperson on given business day and then computes and prints the total number of sales, total amount of sales, and total commission earned by the salesperson. The input is assumed to come from the keyboard, and the input of sale amounts should terminate if the user of the program type 0."

the Q asking for a flowchar but i want in algorathim.

what should i ask the user?

i know that i should ask about the the amount in every sales

should i ask about how many times he sale?

it's easy question but my problem is in logic
here is the last Q for today,please help me to understand the question

"5) A salesperson gets 5% percent commission on sales less than RM1000, 8% percent on sales in the range RM1000 through RM2000, and 10% percent on sales in excess of RM2000. Design a flowchart that reads an arbitrary number of sales made by a salesperson on given business day and then computes and prints the total number of sales, total amount of sales, and total commission earned by the salesperson. The input is assumed to come from the keyboard, and the input of sale amounts should terminate if the user of the program type 0."

the Q asking for a flowchar but i want in algorathim.

what should i ask the user?

i know that i should ask about the the amount in every sales

should i ask about how many times he sale?

it's easy question but my problem is in logic
Pages: 12