Skip to content

Instantly share code, notes, and snippets.

View sojohnnysaid's full-sized avatar
💾

John James sojohnnysaid

💾
View GitHub Profile
@sojohnnysaid
sojohnnysaid / binary.txt
Last active January 19, 2021 22:47
Test gist
0000
8421
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
@sojohnnysaid
sojohnnysaid / hello_world.c
Created December 11, 2017 11:18
A print statement in C
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
@sojohnnysaid
sojohnnysaid / function_example.c
Created December 16, 2017 15:13
Example of a basic function in c
#include <stdio.h>
// add_two_numbers takes 2 arguments, which are 2 numbers, adds them up and returns the result.
int add_two_numbers(x, y)
{
return x + y;
}
int main(void)
{
#include <stdio.h>
int main(void)
{
// example of a simple while loop
// code will continue to execute within the
// while loop brackets until countdown is equal to 0
int countdown = 10;
while (countdown != 0)
#include <stdio.h>
int main(void)
{
// example of a simple for loop
// code will continue to execute within the
// for loop brackets until i is greater than 10
for (int i = 1; i <= 10; i++) // notice incrementing i is built into this type of loop
{
@sojohnnysaid
sojohnnysaid / variable_1.c
Last active January 19, 2021 22:49
Example of how variables work in C
#include<stdio.h>
int main(void){
// Example of using variables to hold data
int number = 90;
char string[] = "That is a great score";
char letter = 'A';
#include <stdio.h>
int main(int argc, char **argv)
{
// A short demo showing the output of bitwise operators
// In C you can express a binary value by prepending it
// with "0b." Below are two variables using this expression
int a = 0b111100; // the number 60
int b = 0b001101; // the number 13
#include <stdio.h>
int main(void){
// Example 2: conditional structures.
int answer = 42;
if (answer == 42) //Only runs the line below if true
printf("You have found the answer! It is %d\n\n", answer);
// Example of how to include the standard IO library in order to use
// common functions that allow input and output from the terminal
#include <stdio.h> // Include directive gives us access to the .h file
int main(void){
char character = 'A';
char string[] = "Hello World";
int number = 42;
float my_float = 20.20;
#include <stdio.h>
#include <cs50.h>
int main(void){
// get_string and get_int are included
// within the cs50 header file
// also note the string data type
// is a part of the cs50 header file
string s = get_string("Prompt name: ");