Skip to content

Instantly share code, notes, and snippets.

@mr-fool
mr-fool / birthday
Last active August 29, 2015 14:00
Assignment 2 for my intro cs classes
#Tested using Python 3.3.0
#Version 10 change from recursive to function to no-function
#Lucky number generator
#Limitation:
#if the inputs are within the range of the loops, the program will assume your inputs are correct
#Program crashs when the input is not integer
#Contains the maximum amount of days in a month
Max_Day=[31,28,31,30,31,30,31,31,30,31,30,31]
#Taking user input
@mr-fool
mr-fool / Circle
Last active August 29, 2015 14:00
Calculating the diameter, circumference and area of a circle
/*Calculate the diameter,circumference and area of a circle
Using C pi*/
/*Including Library*/
#include <math.h>
#include <stdio.h>
int main (void) {
/*Declaring the variable*/
int radius;
@mr-fool
mr-fool / Makefile
Last active August 29, 2015 14:01
A C program that draws hollow circle, hollow rectangle and hollow right triangle
allFiles: draw.c
gcc -Wall draw.c -o draw.out -lm
clean:
rm *.o draw.out
@mr-fool
mr-fool / bin2dec
Last active August 29, 2015 14:01
Number System Conversion in C
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
/*Declaring Constant */
int const BASE = 2;
int const BASE_TEN = 10;
/* converting from decimal require the following information input number,quotient, remainder*/
int inputNumber;
int calculationRemainder;
@mr-fool
mr-fool / Makefile
Last active August 29, 2015 14:02
A program that normalize fractions and simplify it
allFiles: fraction.c
gcc -Wall fraction.c -o fraction.out -lm
clean:
rm *.o fraction.out
@mr-fool
mr-fool / Makefile
Created June 16, 2014 05:11
A program that normalize fractions and simplify it (optimized for large fraction)
allFiles: fraction.c
gcc -Wall fraction.c -o fraction.out -lm
clean:
rm *.o fraction.out
@mr-fool
mr-fool / interest.c
Last active August 29, 2015 14:02
Calculating compound interest
/*Calculating compound interest*/
#include <stdio.h>
#include <math.h>
int main (void) {
double amount;
double principal;
double rate;
int year;
int i;
@mr-fool
mr-fool / mymath.asm
Created June 19, 2014 16:36
a simple math x86 assembly program
; The formula that I am trying to implement is (a+b-c)*d/e
; Caution: will not work with negative and floating point numbers
BITS 32 ;declare it as a 32 bit code
GLOBAL _start
SECTION .text
_start:
mov ebx,4 ;variable a
mov eax,4 ;variable b
mov ecx,5 ;variable c
mov edx,2 ;variable d
@mr-fool
mr-fool / ascii.c
Created June 19, 2014 16:50
A C program that print ascii table using print buff
#include <stdio.h>
#define LOWER_BOUND 33 //since 1-33 is considered nonprintable prof said consider space and tab as nonprintable
#define UPPER_BOUND 127
int main() {
char row[9]; //8 characters a row
int c, d; //d is used to control the bounds of the row buffer
for (d = 0, c = 0; c <= UPPER_BOUND; c++) { // c is the used as the ascii
if (c < LOWER_BOUND || c >= UPPER_BOUND) //1-33 or 127 print .
@mr-fool
mr-fool / ascii.c
Created June 19, 2014 16:51
C printing ascii table without print buffer
#include <stdio.h>
int main(){
int i=0; //
while (i<=127){ /*227 = total number of asii value*/
if (i%8==0 ) {
printf("\n");
}
if ((i<=32) || (i==127) ){ /*Since 1-32 and 127 is non-printable*/
printf("%c",'.'); /*replace non-printable character with .*/