Quiz3 - printf("\nHere is Problem...

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(&quot;\nHere is Problem 2:\n&quot;); printf(&quot;Enter the number of elements (&lt;16):\n&quot;); scanf(&quot;%d&quot;, &amp;n); printf(&quot;\nEnter %d double f-p constants:\n&quot;, n); for(k=0; k&lt;=n-1; k++) { scanf(&quot;%lf&quot;, &amp;a[k]); } printf(&quot;\na as entered:\n&quot;); for(k=0; k&lt;=n-1; k++) { printf(&quot;%.3e\t&quot;, a[k]); if(((k+1)%5) == 0) printf(&quot;\n&quot;); } vlen = unit_vector(a, n); printf(&quot;\nnormalized a:\n&quot;); for(k=0; k&lt;=n-1; k++) { printf(&quot;%.3e\t&quot;, a[k]/vlen); if(((k+1)%5) == 0) printf(&quot;\n&quot;); } printf(&quot;\n||a|| = %.3e\n&quot;, 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

Page1 / 2

Quiz3 - printf(&amp;amp;quot;\nHere is Problem...

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