Skip to content

Instantly share code, notes, and snippets.

@jmichalenko
jmichalenko / monte_hall.c
Created May 12, 2024 13:20
starter code for monte hall project
//monte_hall.c
//Monte Hall Problem is adapted from Rosetta Code
// Content is available under GNU Free Documentation License 1.2 unless otherwise noted.
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#define GAMES 3000000
@jmichalenko
jmichalenko / simulate.c
Created May 12, 2024 13:17
starter code for simulate.c
//simulate.c
/**
* At University High School, 80% of the students are expected to get at
* least a 4 on their APCSP exam. The program below is intended to
* simulate this result with n students, and display the number
* of students who received a 4 or a 5.
**/
#include <cs50.h>
@jmichalenko
jmichalenko / binary.c
Created May 12, 2024 13:14
starter code for binarysearch lab
// implement binary search function
#include <cs50.h>
#include <stdio.h>
#define NUMBERS 9
bool bin_search(int value, int values[], int size);
int main(void)
@jmichalenko
jmichalenko / insertion.c
Created May 12, 2024 13:11
starter code for insertion lab
// complete the insertion_sort function
#include <cs50.h>
#include <stdio.h>
// function prototypes
void insertion_sort(int arr[], int n);
void print_array(int arr[], int n);
// size of array
// complete the selection_sort function
#include <cs50.h>
#include <stdio.h>
// function prototypes
void selection_sort(int arr[], int size);
void print_array(int arr[], int size);
// size of array
@jmichalenko
jmichalenko / bubble.c
Created May 12, 2024 13:02
bubble sort starter code
// complete the bubble_sort function
#include <cs50.h>
#include <stdio.h>
// function prototypes
void bubble_sort(int arr[], int size);
void print_array(int arr[], int size);
// size of array
@jmichalenko
jmichalenko / functions.c
Last active March 22, 2024 17:12
CS50 Labs starter code
#include <cs50.h>
#include <stdio.h>
int get_positive_int(string prompt); //This is called the prototype. It tells the compiler to look for the function below the main function. Note the ;
int main(void)
{
int n = get_positive_int("Enter a positive number: ");
// print the output from our function
@jmichalenko
jmichalenko / multiplication.c
Created March 18, 2024 23:59
CS50 Labs starter code
#include<stdio.h>
#include<cs50.h>
int main (void)
{
//To Do: Write a function to prompt the user for numberA and numberB
//To Do: Write a function to return the product of numberA and numberB. "The product of the number is: "
//After you are able to write the function and compile the program, make a header file and move the function protopye and definition here
//Add the include statement at the top of the file
@jmichalenko
jmichalenko / buggy.c
Created March 18, 2024 23:57
CS50 Labs starter code
#include <stdio.h>
#include <cs50.h>
#include <math.h>
#define BASE 2
// returns true if binary, false if not binary
bool check_binary(int b)
{
while (b > 0)
@jmichalenko
jmichalenko / typecasting.c
Created March 18, 2024 23:54
CS50 Labs starter code
#include <cs50.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
// get a string named plaintext
string plaintext = get_string("plaintext: ");
// output the string