Skip to content

Instantly share code, notes, and snippets.

@towkir
towkir / cellular-tax-calc.py
Last active August 30, 2016 14:37 — forked from maateen/cellular-tax-calc.py
This will take a float number as input and show the total number with tax. (Bangladesh)
#/usr/bin/python3
print("Press 'Ctrl+C' to exit this tool.")
try:
while True:
print("\nPlease input price in BDT: ")
a = raw_input()
try:
float(a)
except ValueError:
@towkir
towkir / nested_to_flat_array.py
Last active October 28, 2016 07:52
This script takes a nested array of integer numbers and returns a flat array
print("This program takes a nested array of integer numbers and returns a flat array")
print("Press Ctrl+C to exit")
try:
while True:
flat_array = []
nested_array = input("Pleas input your arbitrary array:\n")
def loop_through_list(given_list): # this function checks if list items are a list themselves
for a in given_list: # and if so, it calls itself within that list item.
if type(a) == list:
@towkir
towkir / nested_to_flat_array.html
Last active September 8, 2016 01:00
This script takes a nested array of integer numbers and returns a flat array
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Arrays</title>
<style>
body {
font-family: monospace;
margin: 50px;
}
@towkir
towkir / odd_or_even.c
Created September 24, 2016 14:46
This C program checks a number from input and returns if it is even or odd number.
#include <stdio.h>
//a program that checks if a number is Even or Odd
int main() {
int number;
printf("Enter your number:\n");
scanf("%d", &number);
if (number % 2 == 0) {
printf("The number is Even");
} else {
printf("The number is Odd");
@towkir
towkir / positive_or_negative.c
Created September 24, 2016 14:48
This C program checks a number from input and returns if it is positive or negative.
#include <stdio.h>
//a program that checks if a number is positive or negative or nutral
int main() {
int number;
printf("Enter your number:\n");
scanf("%d", &number);
if (number > 0) {
printf("The number is positive");
} else if (number < 0){
printf("The number is negative");
@towkir
towkir / cgpa_checker.c
Created September 28, 2016 15:31
This C program takes a number(mark) as input and returns the grade of that number(mark)
#include <stdio.h>
int main() {
int mark;
printf("Enter your mark:\n");
scanf("%d", &mark);
if (mark <= 100){ //dive in only if mark is less than 100. mark can be negative too
if (mark >= 79) {
printf("Your grade is A+\n");
} else if (mark >= 69) {
@towkir
towkir / prime_or_not.c
Created October 1, 2016 19:37
This C program checks an input number and replies with the result after checking if the number is prime.
#include <stdio.h>
int main() {
int number;
printf("Enter your number:\n");
scanf("%d", &number);
if (number > 3){ // 1,2,3 are prime for sure; verification starts for bigger numbers;
for (int i = 2; i<number; i++){
if (number % i == 0){
printf("The number is not a prime number.\n");
@towkir
towkir / prime_in_range.c
Last active October 4, 2016 14:49
This C program takes a number as input and returns all the prime number between 1 and N (input number)
#include <stdio.h>
int main() {
int range, total_prime_in_range = 0;
printf("Enter your range:\n");
scanf("%d", &range);
printf("The prime numbers in that range are:\n");
for (int i=1; i<=range; i++){//loops through the input numbers
int not_prime = 0;
for (int j=2; j<i/2; j++){
@towkir
towkir / pyramid_star.c
Created October 5, 2016 04:33
This C program takes an odd number (N) as input and returns a pyramid of N row
#include <stdio.h>
int main() {
int rows, i, j, k, spaces, stars;
printf("Enter rows for your pyramid:\n");
scanf("%d", &rows);
spaces = rows -1;
stars = 1;
if (rows % 2 > 0 && rows < 30){
printf("Your pyramid should look like this:\n");
@towkir
towkir / linearsearch.c
Created October 8, 2016 11:11
This C program has an array already saved in the source and it displays it; then requests a number from user, if the input number matches with any one in that array, it returns the position of that number in the array; otherwise, says that it is not in the array;
#include <stdio.h>
int main() {
int data[11] = {10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60};
int entry, i, position=1;
printf("Here is the array:\n");
for (i=0; i<11; i++){
printf("%d\t", data[i]);
}
printf("\n");