Skip to content

Instantly share code, notes, and snippets.

View complxalgorithm's full-sized avatar

Stephen Sanders complxalgorithm

View GitHub Profile
@complxalgorithm
complxalgorithm / callmap.rs
Created May 9, 2016 07:05
Rust program to demonstrate map; goes through all added contacts and calls them, with each calling outputting a saying.
use std::collections::HashMap;
fn call(number: &str) -> &str {
match number {
"798-1364" => "We're sorry, the call cannot be completed as dialed.
Please hang up and try again.",
"645-7689" => "Hello, this is Mr. Awesome's Pizza. My name is Fred.
What can I get for you today?",
_ => "Hi! Who is this again?"
}
@complxalgorithm
complxalgorithm / linearsearchfornuminarray.c
Created May 8, 2016 08:31
C program that implements linear search by inputting a number of values for user to input, and then the user will input a number to see if it was included in the original input (list of numbers).
/*
* C program to input N numbers and store them in an array.
* Do a linear search for a given key and report success
* or failure.
*/
#include <stdio.h>
void main()
{
int array[10];
@complxalgorithm
complxalgorithm / combination.c
Created May 8, 2016 08:28
C program to calculate nCr.
/*
* C program to Calculate the value of nCr
*/
#include <stdio.h>
int fact(int z);
void main()
{
int n, r, ncr;
@complxalgorithm
complxalgorithm / lines.c
Created May 8, 2016 08:26
C program that will collect statistics of a source file, e.g., total lines, total number of blank lines, total number of lines ending with a semicolon, etc. Example: $ cc file8.c $ a.out lines.c The Total number of lines are 23 The Total number of Commented lines are 6 The Total number of blank lines are 4 The total number of lines that end with…
/*
* C Program to Collect Statistics of a Source File like Total Lines,
* Total no. of Blank Lines, Total no. of Lines ending with Semicolon
*/
#include <stdio.h>
#include <stdlib.h>
void main(int argc, char *argv[]) /* Command line Arguments */
{
int ncount = 0, ccount = 0, scount = 0, blank = 0;
@complxalgorithm
complxalgorithm / calculator.py
Created May 8, 2016 08:01
Simple Python calculator program.
# Program make a simple calculator that can add, subtract, multiply and divide using functions
# define functions
def add(x, y):
"""This function adds two numbers"""
return x + y
def subtract(x, y):
"""This function subtracts two numbers"""
@complxalgorithm
complxalgorithm / quadraticequation.py
Created May 8, 2016 07:58
Python program that takes three user input values and uses them to solve the quadratic equation.
# Solve the quadratic equation ax**2 + bx + c = 0
# Coeffients a, b and c are provided by the user
# import complex math module
import cmath
a = float(input('Enter a: '))
b = float(input('Enter b: '))
c = float(input('Enter c: '))
@complxalgorithm
complxalgorithm / calendar.py
Created May 8, 2016 07:57
Python program that outputs calendar for a specific month and year.
# Python program to display calendar of given month of the year
# import module
import calendar
# ask of month and year
yy = int(input("Enter year: "))
mm = int(input("Enter month: "))
# display the calendar
@complxalgorithm
complxalgorithm / filecontents.rs
Created May 8, 2016 07:52
Rust program that outputs contents of a particular file (filename and file content are taken as input). Example: $ echo "Hello World!" > hello.txt $ rustc open.rs && ./open hello.txt contains: Hello World!
// open.rs
use std::error::Error;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
fn main() {
// Create a path to the desired file
let path = Path::new("hello.txt");
let display = path.display();
@complxalgorithm
complxalgorithm / leapyear.c
Created May 8, 2016 07:26
C program that will determine if an input year was/will be a leap year.
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
int main(){
int year;
printf("Type a year (up to 4 digits) to determine if it's a leap year:");
scanf("%d",&year);
getchar();
if(((year<0)||(isalpha(year))||(year>9999))){
printf("Invalid year. Try again.\n");
@complxalgorithm
complxalgorithm / menucommandoptions.csh
Created May 8, 2016 07:21
C-Shell script that will output a menu and allow a user to choose an option that will perform a certain shell command.
#!bin/csh
while(1)
echo "Menu:"
echo "a-List all files in the present working directory."
echo "b-Display today's date and time."
echo "c-Display users currently logged in to server."
echo "d-Display whether a file is an 'ordinary' file or a 'directory'"
echo "e-Create a backup for a file."
echo "x-Exit"
echo -n "->"