Solved

Please Help new to C

Posted on 2006-11-21
7
192 Views
Last Modified: 2010-04-15
Use the program skeleton below (starting with #include <stdio.h>)
as the starting point for quiz4. Add the necessary code to the
functions prob1() and prob2(), and add the other 2 functions, as
described in the text below.

You do not need to change anything in main().

In void prob1(void), take a double floating-point number x from
the keyboard and compute the function f(x), which is defined by:

        f(x) = exp(x)-2*log10(x)+log(x)   if x >=5
        f(x) = 1.5+x*sin(x)               if  -2 < x < 5
        f(x) = x^2+3*x-sinh(x)            if x <= -2.

This function should be computed in:  double func(double x).

In prob1(void), print x and f(x) on the screen.

In void prob2(void), scan the number of elements k that
is less than 9, and the elements of two k-component vectors
v[] and w[]. Print these vectors on the screen.
Then, pass the vectors v[] and w[] and k to a double function
double norm2(double *v, double *w, int k) which will normalize
these two vectors and return the length of the original vector w[].
In prob2(void), print the components of the normalized (unit)
vectors on the screen, as well as the length of the original vector
w[]. If k>5, let 5 components of the vector appear in one line.
*/

/* Program skeleton */
#include <stdio.h>
#include <math.h>
void prob1(void);
void prob2(void);

double func(double x);
double norm2(double *v, double *w, int k);

main()
{
int menu;
printf("There are two functions: prob1() and prob2().\n");
printf("Enter the function number to execute (1 or 2):");
scanf("%d", &menu);
/* form a switch to execute one function */
switch(menu)
{
 case 1:
    prob1();
    break;
 case 2:
    prob2();
    break;
 default:
printf("prob%d() does not exist.\n", menu);
}
exit(0);
}

/*  Problem 1 */
void prob1(void)
{
int x1;
double x;
printf("Here is Problem 1:\n\n");
printf("Enter a double f-p constant:");
/*
scanf("%d", &x1);
if (x1 == -2 || x1 < -2)
{
x == pow(x1, 2) + 3 * x1 - sinh(x1);
}
if (x1 > -2 && x1 < 5)
{
1.5+x*sin(x)
}
if (x1 == 5 or x1 > 5)
{
exp(x)-2*log10(x)+log(x)
}
        f(x) = exp(x)-2*log10(x)+log(x)   if x >=5
        f(x) = 1.5+x*sin(x)               if  -2 < x < 5
        f(x) = x^2+3*x-sinh(x)            if x <= -2.
return;*/
}

double func(double x)
{

}


/*  Problem 2 */
void prob2(void)
{
printf("Here is  Problem 2:\n");

return;
}

double norm2(double *v, double *w, int k)
{

}

.........................

/*

Your output should look like:

iacs5.ucsd.edu% gcc quiz4.c -lm
iacs5.ucsd.edu% a.out

There are two functions: prob1() and prob2().
Enter the function number to execute (1 or 2): 1

Here is Problem 1:

Enter a double f-p constant: -2.5

f(-2.5) = 4.8002

There are two functions: prob1() and prob2().
Enter the function number to execute (1 or 2): 2

Here is Problem 2:

Enter the number of elements (<9): 7

Enter 7 components of v[]
-1 2.0 3.1 -5.2 11.2 -0.25 6.

Enter 7 components of w[]
0.25 -5.1 3.5 1.25 -7.1 0.0 -3.5

v[] as entered:
-1.000    +2.000    +3.100    -5.200    +11.200
-0.250    +6.000

w[] as entered:
+0.250    -5.100    +3.500    +1.250    -7.100
+0.000    -3.500

normalized v[]:
-0.070    +0.140    +0.217    -0.365    +0.786
-0.018    +0.421

normalized w[]:
+0.025    -0.504    +0.346    +0.123    -0.701
+0.000    -0.346

length_w = 10.126

*/
0
Comment
Question by:DARKSAGES
7 Comments
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 17992873
Is this a homework ?
0
 

Author Comment

by:DARKSAGES
ID: 17993372
I'm not asking for them to do my homework, i'm asking for help suggestions on were to start. Mainlly on how to compute these three:

        f(x) = exp(x)-2*log10(x)+log(x)   if x >=5
        f(x) = 1.5+x*sin(x)               if  -2 < x < 5
        f(x) = x^2+3*x-sinh(x)            if x <= -2.
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 17993716
#include <math.h>
if( x >= 5 ){
  f = exp(x)-2*log10(x)+log(x)
...
0
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 18007503
well i would check for float:
if (x >= 5.0){

}
normalizing vectors should be straight forward, asking for v and w is also in the code.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now