Skip to content

Instantly share code, notes, and snippets.

@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
@jmichalenko
jmichalenko / exit.c
Created March 18, 2024 23:51
CS50 Labs starter code
#include <cs50.h>
#include <stdio.h>
int main(int argc, string argv[])
{
if (argc != 3)
{
printf("Usage: ./exit <firstname> <lastname>\n");
}
else
@jmichalenko
jmichalenko / commandline.c
Created March 18, 2024 23:48
CS50 Labs starter code
#include <cs50.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
string name = get_string("Enter your name: ");
// write a for loop to iterate through name and print each char on it's own line
@jmichalenko
jmichalenko / string.c
Created March 18, 2024 23:46
CS50 Labs starter code
#include <cs50.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
string name = get_string("Enter your name: ");
// write a for loop to iterate through name and print each char on it's own line
@jmichalenko
jmichalenko / array.c
Created March 18, 2024 23:44
CS50 Labs starter code
#include <cs50.h>
#include <stdio.h>
# define NUM_DAYS 5
int main(void)
{
int hours[NUM_DAYS];
// write a for loop to prompt for the number of hours for each day
@jmichalenko
jmichalenko / magic.c
Created February 13, 2024 00:40
CS50 Labs Magic Numbers Starter Code
#include <cs50.h>
#include <stdio.h>
#define ONE_YEAR 1
int main(void)
{
// Prompt user for age
int age = get_int("Enter your age: ");
@jmichalenko
jmichalenko / forloop.c
Created February 13, 2024 00:34
CS50 Labs For Loops Starter Code
#include <cs50.h>
#include <stdio.h>
int main(void)
{
for (int i = 0; i < 10; i++)
{
printf("hello, world\n");
}
}