Sunday, October 21, 2012

matrix addition


#include<stdio.h>

#include<conio.h>

void main()

{

  int a[3][3],b[3][3],c[3][3],i,j;

  printf("Enter the First matrix->");

  for(i=0;i<3;i++)

      for(j=0;j<3;j++)

      scanf("%d",&a[i][j]);

  printf("\nEnter the Second matrix->");

  for(i=0;i<3;i++)

      for(j=0;j<3;j++)

           scanf("%d",&b[i][j]);

  printf("\nThe First matrix is\n");

  for(i=0;i<3;i++){

      printf("\n");

      for(j=0;j<3;j++)

           printf("%d\t",a[i][j]);

  }

  printf("\nThe Second matrix is\n");

  for(i=0;i<3;i++){

      printf("\n");

      for(j=0;j<3;j++)

      printf("%d\t",b[i][j]);

   }

   for(i=0;i<3;i++)

       for(j=0;j<3;j++)

            c[i][j]=a[i][j]+b[i][j];

   printf("\nThe Addition of two matrix is\n");

   for(i=0;i<3;i++){

       printf("\n");

       for(j=0;j<3;j++)

            printf("%d\t",c[i][j]);

   }

 

}
.Promote your Website with BidVertiser. Get $20 in FREE clicks.
  DON'T Click Here!
DON'T Click Here!

Monday, October 15, 2012

Fibonacci sequence or series

In mathematics, the Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers in the following integer sequence:

1,\;1,\;2,\;3,\;5,\;8,\;13,\;21,\;34,\;55,\;89,\;144,\; \ldots.
By definition, the first two numbers in the Fibonacci sequence are 0 and 1 (alternatively, 1 and 1), and each subsequent number is the sum of the previous two.
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
F_n = F_{n-1} + F_{n-2},\!\,
with seed values[1]
F_0 = 0,\; F_1 = 1.
The Fibonacci sequence is named after Leonardo of Pisa, who was known as Fibonacci. Fibonacci's 1202 book Liber Abaci introduced the sequence to Western European mathematics,[2] although the sequence had been described earlier in Indian mathematics.[3][4][5] (By modern convention, the sequence begins either with F0 = 0 or with F1 = 1. The Liber Abaci began the sequence with F1 = 1, without an initial 0.)
Fibonacci numbers are closely related to Lucas numbers in that they are a complementary pair of Lucas sequences. They are intimately connected with the golden ratio, for example the closest rational approximations to the ratio are 2/1, 3/2, 5/3, 8/5, ... . Applications include computer algorithms such as the Fibonacci search technique and the Fibonacci heap data structure, and graphs called Fibonacci cubes used for interconnecting parallel and distributed systems. They also appear in biological settings,[6] such as branching in trees, phyllotaxis (the arrangement of leaves on a stem), the fruit spouts of a pineapple,[7] the flowering of artichoke, an uncurling fern and the arrangement of a pine cone.[8]
A tiling with squares whose sides are successive Fibonacci numbers in length
A Fibonacci spiral created by drawing circular arcs connecting the opposite corners of squares in the Fibonacci tiling; this one uses squares of sizes 1, 1, 2, 3, 5, 8, 13, 21, and 34. 

In simple words we can understand that it start from 1,1 and next number is the sum of last two numbers like
   1,1,1+1=2,1+2=3,2+3=5,3+5=8,5+8=13,....
   (  1  ,   1   ,  2    ,3   , 5   ,  8  ,  13  ,...)

so the main logic behind this problem is two take last two no and add them so the next no can be obtain

so the code :
1. while(i<=n-2)

2.{

3  c=a+b;

4. printf("%d ",c);

5. a=b;

6. b=c;

7. i++;

}

take essential part in this program lets have a look at the code:

Statement 1.This is the starting of loop.it shows that loop will iterate upto and equal to n-2.
Statement 2.This is opening curly brace which shows the starting of loop or any block.
Statement 3.This is the addition operation of  last two no.like
                      (1,1) 
                      (a ,b)
                  so what will be c =a+b
                       (1,1,1+1)
                       (a, b,  c )
Statement 4.This is the print function it output next no(c) on the monitor screen
Statement 5 and Statement 6 .In these statement b becomes a and c becomes b like this
                      (1,1,2,1+2 )
                      (a ,b,c, d)
                      (_, b=a',c=b',c'=a'+b'=d)
Statement 7 .finally the increment of the loop variable(i) and end of loop('}')

Code:
//fibonaci series

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int a=1,b=1;

void fibo(int,int);//declaration part of function fibo().

fibo(a,b); //now print rest of the values by return from the function(Calling of fibo()).

getch();//it waits for the user for the input so it holds the input screen until the input is given.

}

void fibo(int a,int b)

{

int n,i=1, c;

printf("enter value  of n:",n);

scanf("%d",&n);

printf("%d ,%d ",a,b);

while(i<=n-2)

{

c=a+b;

printf(", %d ",c);

a=b;

b=c;

i++;

}

}

Output :
               enter value  of n:5
                1, 1 ,2, 3, 5

here red no. (5) is given by user as a input

Friday, October 12, 2012

hello world program


This is the first post my this blog here i will suggest you how to compile and run  c program on windows platform
step 1. first you have to download turboc compiler from this link .this link will contain all the information for or you can watch my video for more help
step 2. unzip the folder(i recommend you to 7zip) and install it.
step 3. write the code and compile & run it. 

for  basic knowledge about the structure or syntax of c source code or program go to my latest tutorial on C "for very beginner".It is very easy to learn tutorial.

If you have any doubt just ask me at my gmail Id kapilsuman18@gmail.com
Code :
// This is a simple hello world program for beginner of C language
#include<stdio.h>
#include<conio.h>
void main()
{
printf("hello world" );
}


Output :

hello world