Showing posts with label hello world. Show all posts
Showing posts with label hello world. Show all posts

Sunday, 12 August 2012

Calculate a PRIME number LIST using C language


This C program calculates a list with first prime numbers.

Build the program


C is a compiled language, so we will need to install a C compiler: gcc
$ sudo aptitude install gcc

We copy this text in a file, e.g: prime_calculator.c

Next we compile the file:
$ gcc -o prime_calculator -lm prime_calculator.c -Wall

or if we want further optimization:
$ gcc -o prime_calculator -lm prime_calculator.c -Wall -O3

-lm option links the math library so we can calculate square roots.

Execute the program


After compilation, an executable appears: prime_calculator.
$ chmod a+x prime_calculator # we grant it execution permission.

If we want to show first ten prime numbers:
$ ./prime_calculator 10
PRIME LIST:
2 3 5 7 11 13 17 19 23 29

If we pass more than two arguments, it calculates the prime list but does not show anything. Just to measure its execution time:
$ time ./prime_calculator 10 *
real 0m0.008s
user 0m0.004s
sys 0m0.000s

Sunday, 29 July 2012

Lua: Calculate a prime number list

Lua is an extension language.


This script calculates a prime number list starting with smaller ones.


To run this script you need to install lua language: (e.g: in Debian or Ubuntu)
$ sudo aptitude install lua

Current version(when this article was written) is 5.1:
$ sudo aptitude install lua5.1


After installing it, lua interpreter could be found in /usr/bin/lua.

Then you copy this script in a file, e.g: primes.lua and exec:

$ lua primes.lua 20 # it will calculate first twenty prime numbers.

or give execution permissions to the file:
$ chmod a+x primes.lua
$ ./primes.lua 20

Wednesday, 25 August 2010

Beginning with Qt: Introduction, Installing Qt Framework, Qt Hello world

INTRODUCTION TO Qt

Qt is a complete development environment widely used to create GUI applications.

This cross-platform tool is also able to create non gui apps.

Qt is used in the KDE desktop environment, and in other projects like virtualbox.


Qt development environment provides: (version numbers when this article was written)

  • Qt libraries (version 4.6.3)
  • Qt Creator IDE (version 2.0.0)
  • Qt development tools


Qt is available under LGPL and GPL free software licenses. Nokia also provides the Qt commercial license to develop proprietary software.


Qt DEVELOPMENT TOOLS

Qt environment provides us with some development tools. e.g:

qmake
qmake tool helps us creating and managing .pro project files, and from them it creates Makefile files needed to build our projects.
qmake Manual
qmake Tutorial

Qt assistant
Qt assistant tool shows all available Qt help. It is a help browsing system.
Qt Assistant Manual

Sunday, 6 July 2008

Hello World program examples

Hello World is the first program every user usually codes when he learns a new programming language.

Its goal is learning the basics to edit, compile and execute a program which sends a "hello world" string to standard output.


We have used an Ubuntu Hardy distro based system. Most commands will serve to other distros as well, like Debian.


BASH Shell Scripting Hello World


bash command line interpreter is usually already installed in your system.

if it is not installed we type: $sudo aptitude install bash


Now we create hello.sh script using whatever text editor we prefer.
e.g: $ gedit hello.sh


Copy this lines into your hello.sh script
#!/bin/bash
echo "hello world"


Bash shell scripting is an interpreted language so we have not to compile anything. We directly execute the shell script file:

We give the shell script execution permissions:
$ chmod a+x hello.sh

and launch the program
$ ./hello.sh


PYTHON Scripting Hello World


If you do not have python installed in your system, exec:

$ sudo aptitude install python