Week 1 Code Examples

// This program does some maths in C

// Week 1 Lecture 2

#include <stdio.h>

int main(void){

    // +, -, *, /, (), %
    // Declare and initialise variable x with 13
    int x = 13; 
    // Declare and initialise varaible y with 40
    int y = 40;
    // Declaring a variable called result
    //int result;

    // Declare and Assignng the sum of x and y to variable result
    int result = y % x;
    
    // Some char maths for funsies
    char letter = 'S';
    char next_letter = letter + 1;
    printf("Letter %c, next letter = %c and %d", letter, next_letter, next_letter);

    printf("The result is: %d\n", result);    

    return 0;
}
// This program will teach you how to take
// input from the terminal - yay! 

// Week 1 Lecture 2

#include <stdio.h>

#define MEANING_OF_LIFE 42
#define PI 3.14

int main(void){
    // Declare a vavriable called number of type int
    int number;
    printf("Enter a number: ");
    // Function called scanf() is used to read input in
    scanf("%d", &number);

    // Declare a variable called decimal of type double
    double decimal;
    printf("Enter a decimal value: ");
    scanf("%lf", &decimal);

    // Declare a variable called character of type char
    char character;
    printf("Enter a character: ");
    scanf(" %c", &character);

    printf("The number entered is: %d\n", number);
    printf("THe decimal entered is: %lf\n", decimal);
    printf("The character entered is: %c\n", character);

    // print out the constant
    printf("The constant is %d\n", MEANING_OF_LIFE);
    return 0;
}
// This program will demonstrate the use of variables
// in C - fun!

// Week 1, Lecture 2

// This line includes the standard C library to let us
// print out to terminal
#include <stdio.h>

int main(void){

    //Declare a variable
    // int number;

    //Initialise a variable
    // number = 42;

    // Declare and initialise all at once
    // int number_two = 13;

    // Declare and initialise a double
    /// double decimal = 3.5;

    // Declare and initialise a char
    char character = 'S';

    // %d - int placeholder
    // %lf - double placeholder
    // %c - char placeholder
    printf("The character is: %c, and the value is %d\n", character, character);

    return 0;
}
// This program is the ultimate
// culmination of tech issues

// week 1

#include <stdio.h>

int main(void){
    printf("Hello, World!\n");
    return 0;
}