Quiz3

# Quiz3 - printf"\nHere is Problem 2\n"...

This preview shows pages 1–2. Sign up to view the full content.

/* Program skeleton */ #include <stdio.h> #include <math.h> /* Function prototypes */ void prob1(void); void prob2(void); double unit_vector(double *x, int cols); int main(void) { 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) { char text [81]; int len, k; len = strlen(text); printf("Here is Problem 1:\n"); while(strlen(gets(text))==0); for(k=0; k<=len-1; k++) { if(text[k] == 'e') printf("e"); else { if(text[k] == ' ') printf(" "); else printf("*"); } }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
return; } /* Problem 2 */ void prob2(void) { double vlen, a[15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int k, n;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printf("\nHere is Problem 2:\n"); printf("Enter the number of elements (<16):\n"); scanf("%d", &n); printf("\nEnter %d double f-p constants:\n", n); for(k=0; k<=n-1; k++) { scanf("%lf", &a[k]); } printf("\na as entered:\n"); for(k=0; k<=n-1; k++) { printf("%.3e\t", a[k]); if(((k+1)%5) == 0) printf("\n"); } vlen = unit_vector(a, n); printf("\nnormalized a:\n"); for(k=0; k<=n-1; k++) { printf("%.3e\t", a[k]/vlen); if(((k+1)%5) == 0) printf("\n"); } printf("\n||a|| = %.3e\n", vlen); return; } double unit_vector(double *x, int cols) { double length=0.0; length = pow(x[0]*x[0]+x[1]*x[1]+x[2]*x[2]+x[3]*x[3]+x[4]*x[4]+x[5]*x[5]+x[6]*x[6]+x[7]*x[ 7]+x[8]*x[8]+x[9]*x[9]+x[10]*x[10]+x[11]*x[11]+x[12]*x[12]+ x[13]*x[13]+x[14]*x[14], 0.5); return length; }...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern