This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0000 | |
8421 | |
0001 = 1 | |
0010 = 2 | |
0011 = 3 | |
0100 = 4 | |
0101 = 5 | |
0110 = 6 | |
0111 = 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) | |
{ | |
printf("Hello World!\n"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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: "); |
OlderNewer