Konstantinovich

Email: 
    konstans@stuy.edu

Office Hours:
    Periods 6,7,8  in room 301
    Note: 6th is my lunch and I tend to be out getting food the 1st 10 minutes of the period


2018-09-21 Strings II

posted Sep 21, 2018, 10:29 AM by Konstantinovich Samuel

If you need a better seat because of vision, OR you have a name you prefer to be called instead of your official first name:

please fill this out: https://goo.gl/forms/JIE8eoHyk4WQXhW93    


Notes in class.

2018-09-18 Hot Swapping

posted Sep 18, 2018, 10:34 AM by Konstantinovich Samuel

In order do this assignment, you need to be able to generate random numbers in c. 
  • Note: On some systems, you may be able to use other functions than the ones described below, but they are not standard for linux, so you should stay away from them for now.
  • Generating a random number in C requires 2 steps
    1. Seeding the random number generator
      1. srand( time(NULL) );
        1. srand(<SEED>) seeds the random number generator with the provided argument.
        2. If you use the same argument to srand() multiple times, you will get the exact same sequence of random numbers.
        3. time(NULL) will return the current EPOCH time, it is commonly used with srand() to get new random sequences. 
    2. Getting a random number
      1. rand(); 
        1. Returns the next random number in the sequence seeded by srand().
        2. Returns an int.
    3. srand() and rand() are both in <stdlib.h>
    4. time() is in <time.h>
And now for the assignment:
  1. Create an array large enough to store 10 ints.
  2. Populate the array with random values.
  3. Set the last value in the array to 0.
  4. Print out the values in this array
  5. Create a separate array large enough to store 10 ints.
  6. USING ONLY POINTERS (that is, do not use the array variables) do the following:
    • Populate the second array with the values in the first but in reverse order
  7. Print out the values in the second array
For this assignment, do not create helper functions, put everything inside main (it won't be too long). We will talk about passing arrays and pointers are function arguments in a few days.

github repo name:
MKS65C-swap

2018-09-14 Pointers

posted Sep 14, 2018, 10:14 AM by Konstantinovich Samuel   [ updated Sep 14, 2018, 10:52 AM ]

Printf Quick reference:
http://www.pixelbeat.org/programming/gcc/format_specs.html
(Because I hate the man pages too)

Homework: Get to the pointer!
Make a repo named: MKS65C-pointy

Write a program pointy.c that:
  1. Declares and initializes an unsigned int to some value > 2.1 billion.
  2. Declare a char * that points to the address of your unsigned int.
    • Yes, I really do mean char *
  3. Print out your int in hex. 
    • The formatting character for a hexadecimal int is: %x
  4. Use your pointer to print out each individual byte of your int.
    • The formatting character for a single byte in hex is %hhx, that is half of half of an integer.
  5. Using your pointer, modify the individual bytes of your int and print out the resulting value in hex and decimal after each modification.
    1. Increment each byte by 1
    2. Increment each byte by 16
  6. Feel free to try other things
NOTE: You do not need anything more than the basic pointer operations and the printf formatting characters to do this assignment. Stay away from confusing posts on stack overflow (and the like).
        

2018-09-13 Repo me

posted Sep 12, 2018, 12:45 PM by Konstantinovich Samuel

Everyone rename your Euler assignment repo as follows:
MKS65C-Euler

2018-09-07 First C Program

posted Sep 7, 2018, 10:24 AM by Konstantinovich Samuel

Homework:
  1. Look at the problems here: http://projecteuler.net/index.php?section=problems
  2. They are all math problems of some sort, pick two and write a c program to solve them.
    • Some good starters are problems 1, 5 and 6
    • Finished early? pick a third, a fourth, a fifth...
  3. Remember, c syntax is the same as java, so all your old friends (if, while, else, for...) are around.
    • You cannot declare a variable in a for loop, but you can initialize it.
    • If you want to create separate functions, do that above main() 
      • You do not need to make separate functions, but if you do, they must be declared before being used.
  4. Use scanf if you need user input (we'll talk about it Monday, but you can run  $ man scanf from the command line to get info on it). This is not required.

1-5 of 5