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

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

View Full Document Right Arrow Icon
/* 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("*"); } }
Background image of page 1

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

View Full DocumentRight Arrow Icon
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;
Background image of page 2
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

This note was uploaded on 05/22/2008 for the course MAE 9 taught by Professor Lubarda during the Fall '07 term at UCSD.

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online