QR Code (Quick Response Code)

qrcode

What is this code? This is called Quick Response Code which can be created using the http://qrcode.kaywa.com

The Image can be scanned using a mobile phone with a Basic VGA Camera and above. You need to download the kaywa reader to your mobile phone (there are some models only supported nokia, sony, samsung, motorola)

  1. Download the Kaywa reader (either jar or sis file)
  2. Open the kaywa reader application
  3. Open the place where the qr code image is available (it may be the screen, LCD projection on the wall, newspaper,etc)
  4. Once the camera took the image, the reader will process the image and then decrypt the message contained inside the image.

Please look at this video for a demo on how QR Code is decoded using a mobile phone. (Phone Model is Nokia 2730)

QR Code Demo

checking system version (for dynamic loading)...

If you encounter the following error,  checking system version (for dynamic loading)... ./configure: 1: Syntax error: Unterminated quoted string
then do the following,

Open the following files under ns-allinone-2.xx/

tcl: file tcl8.x.x/unix/tcl.m4
tk: file tk8.x.x/unix/tcl.m4
otcl: file otcl-1.x/configure.in

In all the above files, you can find the following line
system=MP-RAS-`awk ' { print $3 } '/etc/.relid'`

and change the above line to (just remove the last but one single quote, remember that ‘ is different from ` you need to remove only ‘ and not `)

system=MP-RAS-`awk ' { print $3 } '/etc/.relid`

C Program–Passing an entire array to a function

/*

This program is to pass the entire array to a function

*/

#include <stdio.h>
#include <conio.h>
int maximum(int[],int); //function prototype, 1st parameter is array and the second is integer

int main()
{
    int a[100],i,n,max=0;
    printf("Enter the numbers"); 
    scanf("%d",&n); //get the index number
    for(i=0;i<n;i++) //get the array elements
    {
    scanf("%d",&a[i]);
    }
    max=maximum(a,n); //function call
    printf("Maximum number is %d",max);
    getch();
    return 0;
}

int maximum(int b[],int a) //function implementation
{
    int i,max=b[0];
    for(i=0;i<a;i++)
    if(b[i]>max)
    max=b[i];
    return max;
}

In the function call ie

max=maximum(a,n) where a is the array and n is the number of array elements

the above line can be written as

max = maximum(&a[0],n)

since the array is just a memory address, it is enough to mention the base address (address of the first element) of the array

so the array name is just equivalent to the base address

in the above example

a means &a[0]

C Program–Arrays with Functions (passing Array elements to function)

/*

Program to demonstrate arrays with function in which the array elements are passed as function parameters

*/

#include <stdio.h>
#include <conio.h>
void display(int); //function prototype
int main()
{
    int a[10],i;
    for(i=0;i<10;i++) //getting the array elements
    {
    scanf("%d",&a[i]);
    }
    for(i=0;i<10;i++)
        display(a[i]); //call the function inside the loop, this function called for 10 times
    getch();
    return 0;
}

void display(int a) //function implementation to print the elements, here the parameter is an integer only(means we are passing the array elements)
{
     printf("%d",a);
}

Arrays in C

Arrays in C programming starts with memory addresses. Yes the compiler handles arrays as memory addresses.

  • Similar elements group together with a single name is called array
  • the indexing always starts with 0 and ends at n-1 (if the size of the array is n)
  • Array elements stores in consecutive memory location.

The array elements usually stores in consecutive memory location. For example,

int a[10];  //Array with size 10

the above example is an integer array with size 10 or this array can hold 10 variables.

The elements starts from a[0], a[1], a[2]…..a[9], so totally there are 10 elements.

Array elements values memory address location
a[0] 32 600AH  (This address is called as the base address)
a[1] 34 600EH
a[2] 23 6012H
a[3] 35 6016H
a[4] 45 601AH
a[5] 67 601EH
a[6] 56 6022H
a[7] 1 6026H
a[8] 34 602AH
a[9] 25 602EH

The memory addresses shown above are in hexadecimal, that’s why each address suffixed with a letter H. The memory addresses in each machine will be different.

The base address is the address where the first element of the array is stored. Usually it is represented as &a[0] or simply a.

The entire array is represented as an address by specifying the base address alone to various other elements of C programming like passing array to functions involves sending the base address only.

For the above table, here is the declaration syntax

int a[10]={32,34,23,35,45,67,56,1,34,25};

or

int a[]={32,34,23,35,45,67,56,1,34,25};

A simple program to get some numbers and print them on the screen

int main()

{

int a[10], j; //declaration of array “a” and its index j

printf(“Enter all the 10 numbers”);

for(j=0;j<10;j++) //get the numbers using a for loop which executes for 10 times (0 to 9)

{

scanf(“%d”, &a[j]);

}

for(j=0;j<10;j++) //print the numbers using a for loop which executes for 10 times (0 to 9)

{

printf(“%d”,a[j]);

}

return 0;

}

In the above example, j varies from 0 to 9 which means the loop will execute 10 times for the array a like this

a[j] when j=0 then a[0]

a[j] when j=1 then a[1]

a[j] when j=2 then a[2]…. and so on

like this the input is entered through the keyboard and same for printing the output.

Functions in C

Almost all the programming languages uses functions. Functions are the entities which are grouping a set of statements which do a specific job or set of jobs.

Example: sum of integers, sum of float number, complex number addition.

All the above three can be implemented as a single function or three separate functions.

When someone wants to use that, a function can be simply called.

So function implementation happens as

  • Function prototype or Function declaration
  • Function definition or function implementation
  • Function call

Function prototype

  • It is necessary to specify the name of the function, the parameters and the return type to the compiler that the function is being defined in this program.
  • The prototype ends with a semicolon

syntax:

int sum(int, int); //function prototype

Function Definition

This is the actual function definition which shows the function implementation.

for the above syntax here is the function

int sum(int a, int b)

{

int c;

c=a+b;

return c;

}

The above function is returning an integer, hence int is specified. If a function is not returning any thing, a void can be used.

Function call

The last is the function call, which when being needed a simple call will make the function to work. Here is the example

int main()

{

int x,y,z;

scanf(“%d %d”,&x,&y);

z=sum(x,y); //function call

printf(“The sum is %d”, z);

return 0;

}

Once the function is called, the control goes to the actual implementation and execute the statements inside the function and the value is returned to the main function.

Components of a function

  1. Name of the function
  2. Return type
  3. Parameters or arguments

In the above example

name of the function is : sum()

return type is : int

parameters are: int, int

C Program 4–To check whether a given number is prime or not

A prime number can be divided by 1 and itself, there are no other divisors,

Examples are : 2 3, 5, 7, 11, …..

To find out whether a given number is prime or not, here is the logic

1. Get the number

2. divide the given number from 2 to n-1 (Example if 6 is the number divided by 2,3,4,5 will get the remainder respectively 0,0,2,3)

3. increment a counter to 1 if the remainder is 0

4. if there counter variable is 0, then the given number is prime (because we didn’t get any remainder) else non prime

Here is the program

#include <stdio.h>
#include <conio.h>

int main()
{
    int a,i,count=0;
    printf("enter a"); //Let the given number is a
    scanf("%d",&a); //get the number
    for(i=2;i<a;i++) //divide the number a from 2 to a-1
    {
    if(a%i==0) 
    count++; //increment a counter if the divisibility is 0
    }
    if(count !=0) //if the counter is not zero, then prime
    printf("a is not a prime number");
    else
    printf("a is a prime number");
getch();
return 0;
}

C Program 3 – To check whether a number is Armstrong Number

The armstrong number is of the form 153= 13 + 53 + 33

The input is : 153 or any other number

output: The number is armstrong or not.

Processing: take 153 as an example, remove 3, 5 and 1 in the reverse order (using % operator) and take the power of 3 and add to the sum variable.

if the total sum and the original number, both are same, then that is the arm strong number.

if else, the number is not an armstrong number

#include <stdio.h>
#include <conio.h>

int main()
{
    int original_num, check, temp, sum=0;
    printf("Enter the number to check for armstrong number");
    scanf("%d", &original_num);
// Get the original number
    temp=original_num;
    while(original_num>0)
//run the loop till the number becomes 0
    {
     check=original_num%10; 
//remove the last digit using modulo operator
     sum=sum+check*check*check; //the last digit is taken power to 3 and added to sum
     original_num=original_num/10; //truncate the last digit and run the loop again
     }
     if(sum==temp)
     printf("This is an armstrong number\n");
     else
     printf("This is not an armstrong number \n");
     getch();
     return 0;
}