Skip to content

Instantly share code, notes, and snippets.

View marcoscastro's full-sized avatar

Marcos Castro de Souza marcoscastro

View GitHub Profile
@marcoscastro
marcoscastro / enumeracao.c
Last active January 1, 2016 08:49
Exemplo do uso de enumeração em C
#include <stdio.h>
enum cores{Azul, Branco, Vermelho};
int main()
{
// declaração de uma variável enum
enum cores cor;
// atribui valor Vermelho a variável cor
#include <stdio.h>
int main(int argc, char *argv[])
{
if(argc > 1)
{
printf("Argumentos passados:\n");
int i;
for(i = 1; i < argc; i++)
printf("%s\n", argv[i]);
// Hello World em JavaScript
function hello_javascript() {
var msg = "Hello www.GeeksBR.com"
document.open();
document.write(msg);
document.close();
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Hello GeeksBR!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="helloworld.js">
</script>
</head>
<body onload="hello_javascript()">
# testado na versão do python 3.2.3
# desempacotamento de lista
lista = ["geeks", "br"]
nome1, nome2 = lista
print(nome1, nome2)
# desempacotamento de tupla
tupla = (1, 2)
num1, num2 = tupla
@marcoscastro
marcoscastro / caesar_cipher.py
Last active January 1, 2016 17:39
Implementation of Caesar Cipher
# implementation of caesar cipher
# key - number of rotational positions
def encrypt(text, key):
text_list = list(text)
text_encrypt = ""
for i in text_list:
# check if char is a letter
if (i >= 'a' and i <= 'z') or (i >= 'A' and i <= 'Z'):
if (i >= 'a' and i <= 'z'):
@marcoscastro
marcoscastro / hello_wxpython.py
Created January 1, 2014 09:39
"Hello World" with wxPython
import wx
my_app = wx.App()
frame = wx.Frame(None, -1, "Hello wxPython!")
frame.Show()
my_app.MainLoop()
@marcoscastro
marcoscastro / dec_to_bin.c
Created January 3, 2014 07:19
Transforma um número decimal em binário.
#include <stdio.h>
#define MAX 100
// Programa que converte um número decimal para binário
void mostrar_binario(int n)
{
// casos base: n = 0 ou n = 1
if(n == 0 || n == 1)
{
@marcoscastro
marcoscastro / triangulo_floyd.c
Created January 3, 2014 07:31
Implementação do triângulo de Floyd em C
#include <stdio.h>
// imprime triângulo de floyd até linha N
void mostrar_triangulo(int N)
{
if(N < 1)
return;
int i = 0, qte = 1, num = 1;
@marcoscastro
marcoscastro / exemplo_macros.c
Created January 3, 2014 07:41
Exemplo do uso de macros em C
#include <stdio.h>
#define SOMA(x,y) ((x) + (y))
#define SUB(x,y) ((x) - (y))
#define DIV(x,y) ((x) / (y))
#define MULT(x,y) ((x) * (y))
int main()
{
printf("Soma: %d\n", SOMA(10, 5));