Thursday, 3 December 2015

The Sierpinski Traingle or Gasket

The Sierpinski Triangle is also called Sierpinski Gasket and Sierpinski Sieve.

A Sierpinski triangle or gasket can be constructed by recursively extracting triangular forms from within an original triangle. At each stage of recursion, three times as many triangles are extracted, each being a quarter of the area of those used in previous stage. This leads to another series, which can be summed to show that the total area extracted is equal to the area of the original triangle-no area remains, yet a set of points remains.
 This definition would be circular, if we did not have a base case at which to stop recursion. We shall say, therefore, that a very small Sierpinski gasket is just a very small triangle.

To make a large Sierpinski gasket:

==>Make a small Sierpinski gasket at one of the corners of the outer triangle.
==>Then move to another corner of the outer triangle and make another small Sierpinski gasket.
==>Then move to another corner of the outer triangle and make another small Sierpinski gasket.
==>Then return the turtle to the initial position and heading.

Program for generating a Sierpinski gasket:
 pi=22/7
SIERPINSKI(Level)
  IF Level=0, Poly(1,2*pi/3)
  OTHERWISE
    REPEAT 3 TIMES
        RESIZE 1/2
        SIERPINSKI(Level-1)
        RESIZE 2
        MOVE 1
        TURN 2*pi/3

Let N_n be the number of black triangles after iteration n, L_n the length of a side of a triangle, and A_n the fractional area which is black after the nth iteration. Then

N_n=3^n
L_n=(1/2)^n=2^(-n)
A_n=L_n^2N_n=(3/4)^n.

Saturday, 31 October 2015

Solution to set mp3 song as ringtone in samsung galaxy y duos GT-S6102.


Here's how to set your mp3 as Ringtone:

1. Open any File Manager App

2. Look for folder called "Media" in phone's main directory.(Mostly it doesn't exist, so create it by right clicking & choosing "New folder", then Rename the folder to "media")

3. Inside the "Media folder", you need a folder "Audio". Again if it's not there create it as above.

4. Inside the "Audio folder", create subfolders for the sound categories you want to change:

=>"Ringtones" for the sound files you want to use for incoming calls
=>"Alarms" for the sound files you want to use for alarms
=>"Notifications" for all other alerts such as incoming SMS, emails or alerts from individual apps, etc.

Note==> Lower/Upper case is irrelevant-the folders can be "MEDIA", "Media",  or "media" etc.

Thursday, 22 October 2015

C Tokens

C tokens:

  • C tokens are the basic buildings blocks in C language which are constructed together to write a C program.
  • Each and every smallest individual units in a C program are known as C tokens.
  • C tokens are of six types. They are,
  1. Keywords               (eg: int, while),
  2. Identifiers               (eg: main, total),
  3. Constants              (eg: 10, 20),
  4. Strings                    (eg: “total”, “hello”),
  5. Special symbols  (eg: (), {}),
  6. Operators              (eg: +, /,-,*)

Difference between format specifiers %i and %d in printf?

They are the same when used for output, e.g. with printf.

 But different when used as input specifier e.g. with scanf, where %d scans an integer as a signed decimal number, but %i defaults to decimal but also allows hexadecimal (if preceded by "0x") and octal if preceded by "0".

So "033" would be 27 with %i but 33 with %d.

C Arrow Operator

Arrow operator (->)

Arrow operator is used for accessing members of structure using pointer variable, below is the syntax of arrow operator in c programming –

Syntax of arrow operator

 struct student 
{
  char name[20],
  int roll; 
}*ptr;

Expalanation :

Whenever we declare structure variable then member can be accessed using the dot operator. But when pointer to a structure is used then arrow operator is used.

Both dot and arrow operator serves same function to access member of structure. Lets compare dot operator and arrow operator –

Example1:
 Struct student
{
    char name[20],
    int roll;
}std;
Example2: 
struct student
{
    char name[20]; 
    int roll;
}*ptr;


Access Structure MemberExample 1Example 2
Name is accessed usingstd.nameptr->name
Roll number is accessed usingstd.rollptr->roll

We can conclude that arrow operator is used to access the structure members when we use pointer variable to access it
In case if we want to access the members of structure using ordinary structure variable then we can use dot operator.

C Conditional Operators

Conditional Operators [ ?: ] are also called as Ternary Operator .

Syntax :

expression 1 ? expression 2 : expression 3
 
where
  • expression1 is Condition
  • expression2 is Statement Followed if Condition is True
  • expression2 is Statement Followed if Condition is False
 
 Explanation:
  1. Expression1 is a Boolean Condition i.e it results into either TRUE or FALSE
  2. If result of expression1 is TRUE then expression2 is Executed.
  3. Expression1 is said to be TRUE if its result is NON-ZERO.
  4. If result of expression1 is FALSE then expression3 is Executed.
  5. Expression1 is said to be FALSE if its result is ZERO. 

Example : Check whether Number is Odd or Even 

#include<stdio.h>

int main()
{
  int num;
  printf("Enter the Number : ");
  scanf("%d",&num);
   if(num%2==0)
    printf("\nNumber is Even");
   else
    printf("\nNumber is Odd");
 }

We can write this program as –

#include<stdio.h>

int main()
{
  int num;
  printf("Enter the Number : ");
  scanf("%d",&num);
 (num%2==0)?printf("\nNumber is Even"):printf("\nNumber is Odd");
 }

Note :
Operator that works on 3 operands is called as tertiary operator.

With C arrays, why we can write that a[5] == 5[a]?

The C standard defines the [] operator as follows:

a[b] == *(a + b)

Therefore a[5] will evaluate to: *(a + 5)
 
and 5[a] will evaluate to:

*(5 + a)
 
and we know those are equal. (Addition is commutative.)

This is the direct artifact of arrays behaving as pointers, "a" is a memory address. "a[5]" is the value that's 5 elements further from "a". The address of this element is "a + 5". This is equal to offset "a" from "5" elements at the beginning of the address space (5 + a).