lab4 - i=0; while ( (text1[i] = message[i]) != '\0' ) i++;

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

View Full Document Right Arrow Icon
Doug Rivas M5-7 ME 218 Lab 4 4.1 #include <stdio.h> int main(void) { int ac; ac= 281; int* acPtr; acPtr= &ac; printf("area code= %d\n", ac); printf("area code= %d\n", *acPtr ); printf("pointer adress: %d", &ac); } 4.2/ 4.3 #include <stdio.h> #include <math.h> void main() { float x[8];
Background image of page 1

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

View Full DocumentRight Arrow Icon
//float *fp; int i; for (i = 0; i <8; i++) x[i] = pow(2,i+1); for (i = 0; i < 8; i++) printf(" %d %f \n", i, x[i]); //fp = x; } 4.4 The value returned by strcmp(message, text1) is : -132 The value returned by strcmp(message, newmessage) is : -5 These two values are a string function comparing the statements by analyzing them as arrays of characters in which each letter has a value. If the strcmp of 2 char is equal, then the two arrays are the same. # include <stdio.h> # include <string.h> void main() {
Background image of page 2
char text1[100]; int i; char newmessage[] = "ME 218"; char message[] = "Hello, I am a string; what are you?"; printf("Original message: %s\n", message); int a= strcmp(message, text1); int b= strcmp(message, newmessage); int c= strlen(message); int d= strlen(text1);
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: i=0; while ( (text1[i] = message[i]) != '\0' ) i++; printf(&quot;text1: %s\n&quot;, text1); printf(&quot;strcmp(message, text1) equals %d\n&quot;, a); printf(&quot;strcmp(message, newmessage) equals %d\n&quot;, b); printf(&quot;The length of 'message' is %d\n&quot;, c); printf(&quot;The length of 'text1' is %d\n&quot;, d); } 4.5 # include &lt;stdio.h&gt; void bin (int); int main (void) { unsigned int num; unsigned int num1; unsigned int num2; unsigned int num3; printf (&quot;Enter the number to be converted into binary\n&quot;); scanf (&quot;%d&quot;,&amp;num1); printf (&quot;Enter the number to be converted into binary\n&quot;); scanf (&quot;%d&quot;,&amp;num2); printf (&quot;Enter the number to be converted into binary\n&quot;); scanf (&quot;%d&quot;,&amp;num3); printf(&quot;The binary equivalent of the first number is :\n&quot;); bin (num1); printf(&quot;\nThe binary equivalent of the second number is :\n&quot;); bin (num2); printf(&quot;\nThe binary equivalent of the third number is :\n&quot;); bin (num3); } void bin (int num) { while (num != 0) { printf (&quot;%d&quot;,num % 2); num = num /2; } }...
View Full Document

This note was uploaded on 04/07/2008 for the course ME 218 taught by Professor Unknown during the Spring '08 term at University of Texas at Austin.

Page1 / 5

lab4 - i=0; while ( (text1[i] = message[i]) != '\0' ) i++;

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

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