Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 253 Lecture 3. Let’s look again at …  the program from the end of the last class.  Here’s the start, and the power function:  the program from.

Similar presentations


Presentation on theme: "CSC 253 Lecture 3. Let’s look again at …  the program from the end of the last class.  Here’s the start, and the power function:  the program from."— Presentation transcript:

1 CSC 253 Lecture 3

2 Let’s look again at …  the program from the end of the last class.  Here’s the start, and the power function:  the program from the end of the last class.  Here’s the start, and the power function: #include int pow(int base, int exp) { int x = base; int i; for (i = 1; i < exp; i++) x = x*base; return x; }

3 Here’s the main program  int main() {  int i;  int x=-2;  long int xx;  printf("The int value of -2 in hex is %x\n",x);  printf("The int value of -2 in octal is %o\n",x);  x=-1;  printf("The int value of -1 in hex is %x\n",x);  printf("The int value of -1 in octal is %o\n",x);  for (i = 1; i < 34; i++) {  xx = pow(2, i);  printf("2^%d -- Unsigned: %u; signed: %i; hex: %x\n", i, xx, xx, xx);  }  xx = pow(2, 31);  printf("xx-1: %i; xx: %i\n", xx-1, xx);  return EXIT_SUCCESS;  int main() {  int i;  int x=-2;  long int xx;  printf("The int value of -2 in hex is %x\n",x);  printf("The int value of -2 in octal is %o\n",x);  x=-1;  printf("The int value of -1 in hex is %x\n",x);  printf("The int value of -1 in octal is %o\n",x);  for (i = 1; i < 34; i++) {  xx = pow(2, i);  printf("2^%d -- Unsigned: %u; signed: %i; hex: %x\n", i, xx, xx, xx);  }  xx = pow(2, 31);  printf("xx-1: %i; xx: %i\n", xx-1, xx);  return EXIT_SUCCESS;

4 How could we change it to …  stop when the unsigned number was first different from the signed number?  print just the largest int & largest unsigned int?  print the numbers in nice columns?  i  signed value of 2 i  unsigned value of 2 i  octal value of 2 i  hex value of 2 i  stop when the unsigned number was first different from the signed number?  print just the largest int & largest unsigned int?  print the numbers in nice columns? ii  signed value of 2 i  unsigned value of 2 i  octal value of 2 i  hex value of 2 i

5 Now let’s try character I/O  Write a program to read a character, then print  the character just read, and  its octal value.  Write a program to read a character, then print  the character just read, and  its octal value.

6 Now string input …  Write a program to read a hex string and print  its character equivalent, and  the string just read  Write a program to read a hex string and print  its character equivalent, and  the string just read

7 Now let’s write a program to…  print out the sizes of  short int s  int s  long int s  float s  double s  print out the sizes of  short int s  int s  long int s  float s  double s


Download ppt "CSC 253 Lecture 3. Let’s look again at …  the program from the end of the last class.  Here’s the start, and the power function:  the program from."

Similar presentations


Ads by Google