Week 1 Code Examples

#include <stdio.h>

int main(void) {

    char initial;

    // "J" -> this is not a character, this is a string
    initial = 'J';

    printf("%c\n", initial+1);

    return 0;
}
#include <stdio.h>

int main(void) {
    double a = 112.5;
    double b = 3.2;

    double result;

    result = a + b; // should 5.7

    printf("%.2lf\n", result); // but prints 5? WTHelly Jake???
    printf("%lf\n", result);
    return 0;
}
#include <stdio.h>

int main(void) {
    printf("Hello everyone!");

    while(1);

    return 0;
}
#include <stdio.h>

int main(void) {
    // \n = new line
    printf("My variables program\n");

    // type name
    // this asks the os for some memory, but does nothing with it.
    int drinking_age;
    drinking_age = 18;
    // oh no, americans
    drinking_age = 21;

    // declares an integer (32 bits from the OS)
    // asks the user for their age
    // assigns it to my_age
    int my_age;
    printf("Enter your age: ");
    scanf("%d", &my_age)

    printf("My age is %d, and the drinking age is %d\n", my_age, drinking_age);

    return 0;
}