Skip to content

Instantly share code, notes, and snippets.

View techstackmedia's full-sized avatar
🏠
Working from home

Bello Osagie techstackmedia

🏠
Working from home
View GitHub Profile
@techstackmedia
techstackmedia / advanced.c
Created July 16, 2023 14:06
Understanding Variables, Conditionals, Loops, and Arrays in C Programming
#include <stdio.h>
#include <string.h> // for string build in function, strlen
int main()
{
const int firstNumber = 30;
const int secondNumber = 50;
const int day = 2;
const int myNumbers[] = {4, 6, 9, 20, 5, 10};
const char *myLanguages[] = {"C", "C++", "Java", "C#", "PHP", "Python", "Ruby", "JavaScript", "Rust", "Go", "Swift", "R", "Kotlin"};
@techstackmedia
techstackmedia / intermediate.c
Created June 25, 2023 01:11
manipulating string based on the functions provided by string.h library.
#include <stdio.h>
#include <string.h>
int main(void) {
const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char firstText[50] = "Hello ";
const char secondText[] = "World!";
const int alphabetLength = strlen(alphabet);
const int alphabetByte = sizeof(alphabet);
const char firstStr[] = "Happy";
@techstackmedia
techstackmedia / basics.c
Created June 20, 2023 13:27
Basic of C - Data Types, Constant Variables, Comments, Array, Print function
#include <stdio.h>
#include <stdbool.h>
/*
* Run:
* gcc -Wall -pedantic -Werror -Wextra -std=c99 c-programming/input.c -o c-programming/output
* gcc c-programming/input.c -o c-programming/output
* c-programming/output
*/
@techstackmedia
techstackmedia / hello.c
Created June 20, 2023 00:35
A simple "Hello, World!" program in C
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
# Python as calculator
x, y = 9, 3
print(x + y) # Addition
# 12
print(x - y) # Subtraction
# 6
print(x * y) # Multiplication
# Complex function conversion
# A different data type can be converted to a complex number
# Conversion of integer numbers to a complex number
# You can provide an argument to a complex() function
z = complex(10, 20)
print(z)
# (10+20j)
complex('10', '20')
# Traceback (most recent call last):
z = 2 + 17.6j
print(z)
# (2 + 17.6j)
print(z.real)
# 2.0
print(z.imag)
# 17.6
print(z.conjugate())
# (2-17.6j)
# Number - Integer, Float, Complex
# Integer
Integer in Python are numbers without decimal e.g 20
# A different data type can be converted to an integer
# Integer conversion is done with the int() function
book_price = 20
print(book_price)
# 20
book_price = '30'
print(int(book_price))
# Primitive Data Structures (Types)
# All Primitive Data Types are Immutable Objects
int_ = 5 # int - Immutable Object
float_ = 5.25 # float - Immutable Object
complex_ = 2 + 7.25j # complex - Immutable Object
str_ = 'This is a text' # str - Immutable Object
bool_ = False # bool - Immutable Object
type(int_) # int - Integer Numbers
# <class 'int'>
isinstance('Hello', (float, int, str, list, dict, tuple))
# True