Most Commonly Used Git Commands

usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--   info-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[-c name=value] [--help] <command> [<args>]


The most commonly used git commands are:
add            Add file contents to the index
bisect         Find by binary search the change that introduced a bug
branch        List, create, or delete branches
checkout     Checkout a branch or paths to the working tree
clone          Clone a repository into a new directory
commit       Record changes to the repository
diff             Show changes between commits, commit and working tree, etc
fetch           Download objects and refs from another repository
grep           Print lines matching a pattern
init              Create an empty git repository or reinitialize an existing one
log              Show commit logs
merge         Join two or more development histories together
mv              Move or rename a file, a directory, or a symlink
pull              Fetch from and merge with another repository or a local branch
push            Update remote refs along with associated objects
rebase         Forward-port local commits to the updated upstream head
reset           Reset current HEAD to the specified state
rm              Remove files from the working tree and from the index
show           Show various types of objects
status          Show the working tree status
tag              Create, list, delete or verify a tag object signed with GPG

Git: Installation & Setup

Installation:

1) Ubuntu,debian
           sudo apt-get install git-core
2) Fedora,red hat
           yum install git
3) Windows
           http://code.google.com/p/msysgit/
4) Mac OS
           http://code.google.com/p/git-osx-installer 

Setting up Git:

When you first start using Git, there are a few things you will likely want to get setup before you start. Git records your name and email address when you create commits, so you need to tell Git what those are. 

You can use the git config command to set those. If you pass --globalit will save the values in the ‘~/.gitconfig’ file so they are the default for all of your repositories.

User Configuration:

          $ git config --global user.name "Your Name" 
          $ git config --global user.email "YourMail@gmail.com"

Push configuration:

The following command configure Git so that the git push command pushes always all branches which are connected to a remote branch (configured as remote tracking branches) to your Git remote repository. This makes is typical easier to ensure that all relevant branches are pushed.

# set default so that all changes are always pushed to the repository 
         $ git config --global push.default "matching"

Avoid merge commits for pulling:

If you pull in changes from a remote repository, Git by default creates merge commits. This typically undesired and you can avoid this via the following setting.

# set default so that you avoid unnecessary commits 
        $ git config --global branch.autosetuprebase always

Color Highlighting:

       $ git config --global color.ui true 
       $ git config --global color.status auto 
       $ git config --global color.branch auto

Setting the default editor:


       $  git config --global core.editor vim

What is Git?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Git allows groups of people to work on the same documents (often code) at the same time, and without stepping on each other's toes. It's a distributed version control system.

Git is a distributed system, everyone has their own copy of the source codes.

Distributed version control system:
A distributed version control system has not necessary a central server which stores the data.


The user can copy an existing repository. This copying process is typically called cloning in a distributed version control system.

Typically there is a central server for keeping a repository but each cloned repository is a full copy of this repository. The decision which of the copies is considered to be the central server repository is a pure convention and not tied to the capabilities of the distributed version control itself.

Every local copy contains the full history of the collection of files and a cloned repository has the same functionality as the original repository.

Every repository can exchange versions of the files with other repositories by transporting these changes. This is typically done via the selected central server repository.

C Program to Print a pyramid string triangle

#include <stdio.h>
#include <string.h>
int main()
{
         int i,j,length;
         char arr[] = "Programming";
         length = strlen(arr);
         for (i = length; i >= 0; i--)
        {
            printf("\n");
           for (j = 0; j< i; j++)
          {
                  printf("%c",arr[j]);
          }
       }
     return 0;
}
Output:
Programming
Programmin
Programmi
Programm
Program
Progra
Progr
Prog
Pro
Pr
P

C Program to count Number of Words in a Line

#include<stdio.h>
#include<string.h>
void main()
{
        char str[20];
        char *p;
        int count=0;
        clrscr();
        printf("Enter the Line:");
        gets(str);
        p=str;

        while(*p!='\0')
        {
              if(*p=='')
              {
                       count++;
              }
              p++;
        }
        printf("The number of Word is: %d",count+1);
        getch();
}
Output:
Enter the Line: C Programming Language
The number of Word is: 3

Find The Output Of Following Code?

#include<stdio.h>
#include<conio.h>
void main()
{
           clrscr();
           int i=5,j=5,k=5;
           i= i++ * ++i;
           j= ++j * ++j;
           k= k++ * k++;

           printf("%d\n",i);
           printf("%d\n",j);
           printf("%d\n",k);
           getch();
}

Output:

37
49
27

Explanation:
i=i++ * ++i; 
it reads from right to left
so first i increments so i=++i * 6;
Now i value is 6 so multiply 6 * 6=36
then perform post increment in i so Value becomes 37

j & K output is also same as above explanation.

Write a C program to reverse the given number and check if the number is palindrome.

int main()
{
  int n, reverse=0, rem,temp;
  printf("Enter an integer: ");
  scanf("%d", &n);
  temp=n;
  while(temp!=0)
  {
     rem=temp%10;
     reverse=reverse*10+rem;
     temp/=10;
  }  
/* Checking if number entered by user and it's reverse number is equal. */  
  if(reverse==n)  
      printf("%d is a palindrome.",n);
  else
      printf("%d is not a palindrome.",n);
  return 0;
}
Output:
Enter an integer: 12321
12321 is a palindrome.

Write a C program to find the sum of the first 15 even numbers and calculate the square of the sum

void main()
{
     int c=1,i;
     unsigned int s=0;
     for(i=1;i<=15;i++)
     {
        if(i%2==0)
        {
            s=s+i;
            c=c+i;
        }
     }
     printf("Sum of the first 15 even numbers is: %d",s);
     printf("Square of the sum is: %d",(s*s));
}

Write a C program to find the total and average of the marks given in an array.

void main()
{
     int i;
     int Avg;
     int maks[20]; 
     clrscr();
     sum=0;
     for(i=0;i<=9;i++)
     {
           printf(" Enter Marks/n ");
           scanf("%d",&marks[i] );   
     }
     for(i=0;i<=9;i++)
     {
           sum = sum + marks[i];
           Avg = sum/10;
           printf(" Total= %d\n" , sum);
           printf(" Average Marks = %d\n" , Avg);
     }
} 

Write a C program to search the given number in an array using binary search

int main()
{

    int a[10],i,n,m,c,l,u;

    printf("Enter the size of an array: ");
    scanf("%d",&n);

    printf("Enter the elements of the array: " );
    for(i=0;i<n;i++)
    {
         scanf("%d",&a[i]);
    }

    printf("Enter the number to be search: ");
    scanf("%d",&m);

    l=0,u=n-1;
    c=binary(a,n,m,l,u);
    if(c==0)
         printf("Number is not found.");
    else
         printf("Number is found.");

    return 0;
}
int binary(int a[],int n,int m,int l,int u)
{

     int mid,c=0;

     if(l<=u)
     {
          mid=(l+u)/2;
          if(m==a[mid])
          {
              c=1;
          }
          else if(m<a[mid])
          {
              return binary(a,n,m,l,mid-1);
          }
          else
              return binary(a,n,m,mid+1,u);
     }
     else
          return c;
}
Output:
Enter the size of an array: 5
Enter the elements of the array: 8 9 10 11 12
Enter the number to be search: 8
Number is found.

Write a C program to convert the given decimal number to binary, Octal and Hexadecimal

Convert Decimal to Binary:
int main()
{
    long int decimalNumber,remainder,quotient;
    int binaryNumber[100],i=1,j;
    printf("Enter any decimal number: ");
    scanf("%ld",&decimalNumber);
    quotient = decimalNumber;
    while(quotient!=0){
         binaryNumber[i++]= quotient % 2;
         quotient = quotient / 2;
    }
    printf("Equivalent binary value of decimal number %d: ",decimalNumber);
    for(j = i -1 ;j> 0;j--)
         printf("%d",binaryNumber[j]);

    return 0;
}
output:
Enter any decimal number: 50
Equivalent binary value of decimal number 50: 110010
Convert Decimal to Octal:
int main(){
  long int decimalNumber,remainder,quotient;
  int octalNumber[100],i=1,j;

  printf("Enter any decimal number: ");
  scanf("%ld",&decimalNumber);

  quotient = decimalNumber;
  while(quotient!=0){
      octalNumber[i++]= quotient % 8;
      quotient = quotient / 8;
  }
  printf("Equivalent octal value of decimal number %d: ",decimalNumber);
  for(j = i -1 ;j> 0;j--)
      printf("%d",octalNumber[j]);
  return 0;
}
Output:
Enter any decimal number: 50
Equivalent octal value of decimal number 50: 62

2. Easy way to convert decimal number to octal number in c
#include
int main(){
  long int decimalNumber;
  printf("Enter any decimal number : ");
  scanf("%d",&decimalNumber);
  printf("Equivalent octal number is: %o",decimalNumber);
  return 0;
}
output:
Enter any decimal number: 25
Equivalent octal number is: 31
Convert Decimal to Hexadecimal:
int main(){
    long int decimalNumber,remainder,quotient;
    int i=1,j,temp;
    char hexadecimalNumber[100];

    printf("Enter any decimal number: ");
    scanf("%ld",&decimalNumber);

    quotient = decimalNumber;

    while(quotient!=0){
         temp = quotient % 16;

      //To convert integer into character
      if( temp < 10)
           temp =temp + 48;
      else
         temp = temp + 55;

      hexadecimalNumber[i++]= temp;
      quotient = quotient / 16;
  }

    printf("Equivalent hexadecimal value of decimal number %d: ",decimalNumber);
    for(j = i -1 ;j> 0;j--)
      printf("%c",hexadecimalNumber[j]);

    return 0;
}

Output:

Enter any decimal number: 45
Equivalent hexadecimal value of decimal number 45: 2D

2. Easy way to convert decimal number to hexadecimal number:

#include
int main(){

  long int decimalNumber;

  printf("Enter any decimal number: ");
  scanf("%d",&decimalNumber);

  printf("Equivalent hexadecimal number is: %X",decimalNumber);

  return 0;
}

Output:
Enter any decimal number: 45
Equivalent hexadecimal number is: 2D

Write a C program to generate a multiplication table

int main(){
  int r,i,j,k;
  printf("Enter the number range: ");
  scanf("%d",&r);
  for(i=1;i<=r;i++){
      for(j=1;j<=10;j++)
           printf("%d*%d=%d ",i,j,i*j);
      printf("\n");
  }
  return 0;
}

Output:
Enter the number range: 5

1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9 1*10=10

2*1=2 2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18 2*10=20
3*1=3 3*2=6 3*3=9 3*4=12 3*5=15 3*6=18 3*7=21 3*8=24 3*9=27 3*10=30
4*1=4 4*2=8 4*3=12 4*4=16 4*5=20 4*6=24 4*7=28 4*8=32 4*9=36 4*10=40
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45 5*10=50

Write a C program to demonstrate passing structures to functions.

In C, structure can be passed to functions by two methods: 1) Passing by value (passing actual value as argument) 2) Passing by reference (passing address of an argument) Passing structure by value:
#include 
struct student{
    char name[50];
    int roll;
};
void Display(struct student stu);
/* function prototype should be below to the structure declaration otherwise compiler shows error */
int main(){
    struct student s1;
    printf("Enter student's name: ");
    scanf("%s",&s1.name);
    printf("Enter roll number:");
    scanf("%d",&s1.roll);
    Display(s1);   // passing structure variable s1 as argument
    return 0;
}
void Display(struct student stu){
  printf("Output\nName: %s",stu.name);
  printf("\nRoll: %d",stu.roll);
}
Output:
Enter student's name: Kevin Amla
Enter roll number: 149
Output
Name: Kevin Amla
Roll: 149
Passing structure by reference:
#include 
struct distance{
    int feet;
    float inch;
};
void Add(struct distance d1,struct distance d2, struct distance *d3); 
int main()
{
    struct distance dist1, dist2, dist3;
    printf("First distance\n");
    printf("Enter feet: ");
    scanf("%d",&dist1.feet);
    printf("Enter inch: ");
    scanf("%f",&dist1.inch);
    printf("Second distance\n");
    printf("Enter feet: ");
    scanf("%d",&dist2.feet);
    printf("Enter inch: ");
    scanf("%f",&dist2.inch);
    Add(dist1, dist2, &dist3); 

/*passing structure variables dist1 and dist2 by value whereas passing structure variable dist3 by reference */
    printf("\nSum of distances = %d\'-%.1f\"",dist3.feet, dist3.inch);
    return 0;
}
void Add(struct distance d1,struct distance d2, struct distance *d3) 
{
/* Adding distances d1 and d2 and storing it in d3 */
     d3->feet=d1.feet+d2.feet; 
     d3->inch=d1.inch+d2.inch;
     if (d3->inch>=12) {     /* if inch is greater or equal to 12, converting it to feet. */
         d3->inch-=12;
         ++d3->feet;
    }
}
Output:
First distance
Enter feet: 12
Enter inch: 6.8
Second distance
Enter feet: 5
Enter inch: 7.5

Sum of distances = 18'-2.3"

How to swap two numbers in c without using third variable

#include
int main(){

    int a=5,b=10;

    //process one
    a=b+a;
    b=a-b;
    a=a-b;
    printf("a= %d  b=  %d",a,b);

    //process two
    a=5;b=10;
    a=a+b-(b=a);
    printf("\na= %d  b=  %d",a,b);

    //process three
    a=5;b=10;
    a=a^b;
    b=a^b;
    a=b^a;
    printf("\na= %d  b=  %d",a,b);

    //process four
    a=5;b=10;
    a=b-~a-1;
    b=a+~b+1;
    a=a+~b+1;
    printf("\na= %d  b=  %d",a,b);

    //process five
    a=5,b=10;
    a=b+a,b=a-b,a=a-b;
    printf("\na= %d  b=  %d",a,b);

    return 0;
}

Wrie a C program to print Pascal triangle using for loop

long fact(int);
int main()
{
    int line,i,j;

    printf("Enter the no. of lines: ");
    scanf("%d",&line);

    for(i=0;i<line;i++){
         for(j=0;j<line-i-1;j++)
             printf(" ");

         for(j=0;j<=i;j++)
             printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
         printf("\n");
    }
    return 0;
}
long fact(int num)
{
    long f=1;
    int i=1;
    while(i<=num)
    {
         f=f*i;
         i++;
    }
  return f;
}
Output:
Enter the no. of lines: 8
        1
      1  1
    1  2  1
  1  3  3  1
1  4  6  4  1

Check given number is prime number or not using c program

Definition of prime number: A natural number greater than one has not any other divisors except 1 and itself. In other word we can say which has only two divisors 1 and number itself. 

For example: 5 Their divisors are 1 and 5. 
Note: 2 is only even prime number. 

Logic for prime number in c: We will take a loop and divide number from 2 to number/2. If the number is not divisible by any of the numbers then we will print it as prime number. 

 Example of prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199 etc. 

 Find given number is prime or not:
int main(){

    int num,i,count=0;
    printf("Enter a number: ");
    scanf("%d",&num);
    for(i=2;i<=num/2;i++){
        if(num%i==0){
         count++;
            break;
        }
    }
   if(count==0 && num!= 1)
        printf("%d is a prime number",num);
   else
      printf("%d is not a prime number",num);
   return 0;
}

Output:
Enter a number: 5
5 is a prime number
To Print Prime numbers from 1 to 100:
int main(){
    int num,i,count;
  
    for(num = 1;num<=100;num++){
         count = 0;

         for(i=2;i<=num/2;i++){
             if(num%i==0){
                 count++;
                 break;
             }
        }
        
         if(count==0 && num!= 1)
             printf("%d ",num);
    }
  
   return 0;
}

Output:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Write a C program whether the given number is Perfect number or not.

Definition of Perfect number: A positive integer n is called a perfect number if it is equal to the sum of all of its positive divisors, excluding n itself.


For example, 6 is perfect integer number, because 1, 2 and 3 are its proper positive divisors and 1+2+3=6.

The next perfect number is 28 because 1+2+4+7+14=28.
The next perfect number is 496 because
1+2+4+8+16+31+62+124+248=496.
/*program to check whether a number is perfect or not*/

#include<stdio.h>
#include<conio.h>
int main()
{
        int i,n,num,sum=0;
        printf("Enter a number : ");
        scanf("%d",&num);
        n=num;
        for(i=1; i<n; i++)
        {
               if(num%i==0)
                       sum=sum+i;
        }
        if(num==sum)
              printf("Given number is Perfect Number ");
        else
              printf("Given number is Not Perfect Number ");
    getch();
return 0;
}

Output:-
Enter a number : 7543
Given number is Not Perfect Number

Enter a number : 8128
Given number is Perfect Number

Write a C program to add, subtract, multiply and divide two numbers using functions

int add (int x, int y)
{
    int z;
    z = x + y;
    return (z);
}
int sub(int x, int y)
{
    int z;
    z = x - y;
    return (z);
}
int mul(int x, int y)
{
    int z;
    z = x * y;
    return (z);
}
int div(int x, int y)
{
    int z;
    z = x / y;
    return (z);
}
main ()
{
    int i,j,k,l,m,n;
    i = 10;
    j = 20;
    k = add(i, j); 
    l=sub(i,j);
    m=mul(i,j);
    n=div(i,j);
    printf("\n Sum %d",k);
    printf("\n Subtraction %d",l);
    printf("\n Multiplication %d",m);
    printf("\n divide %d",n);
}

Write a C program for matrix addition

Rule: Addition of two matrices is only possible if both matrices are of same size.
int 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]);
   }
   return 0;
}

Write a C program for matrix subtraction

Rule: Subtraction of two matrices is only possible if both matrices are of same size. Suppose two matrices A and B is of same size m X n Subtraction of two matrices is defined as (A - B)ij = Aij - Bij Where 1 ≤ i ≤ m and 1 ≤ j ≤ n
int 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 Subtraction 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]);
   }
   return 0;
}

Write a C program to transpose the given matrix

Transpose: Transpose of a Matrix means changing Rows into Columns and vice-versa.
void main()
{
     int A[2][3] , B[3][2];
     int i, j;               /* 'i' used for rows and 'j' used for columns */
     clrscr();
     printf(" Enter the elements of A\n");
     for(i=0 ; i<2 ; i++)
     {
        for(j=0 ; j<3 ; j++)
        {
          scanf("%d" , &A[i][j] );
        }
     }
     printf(" Matrix is\n");
     for(i=0 ; i<2 ; i++)
     {
        for(j=0 ; j<3 ; j++)
        {
              printf("%d\t",A[i][j] );        /* '\t' used for Tab */ 
        }                                                          
        printf("\n");           /* '\n' used for next line character */
     }
     for(i=0 ; i<3 ; i++)
     {
         for(j=0 ; j<2 ; j++)
         {
              B[i][j] = A[j][i];
         }
     }
     printf(" After Transpose\n");
     for(i=0 ; i<3 ; i++)
     {
         for(j=0 ; j<2 ; j++)
         {
              printf("%d\t" , B[i][j] );                            
         }                                                           
         printf("\n");                                      
     }
     getch();
} 

Write a C program to find string palindrome without using String functions

int main()
{
   char text[100];
   int begin, middle, end, length = 0;
 
   gets(text);
 
   while ( text[length] != '\0' )
      length++;
 
   end = length - 1;
   middle = length/2;
 
   for( begin = 0 ; begin < middle ; begin++ )
   {
      if ( text[begin] != text[end] )
      {
         printf("Not a palindrome.\n");
         break;
      }
      end--;
   }
   if( begin == middle )
      printf("Palindrome.\n");
 
   return 0;
}

Write a C program for demonstrating Tower of Hanoi using Recursion

#include
#include
#include
void hanoi(int x, char from, char to, char aux)
{
    if(x==1)
    printf("Move Disk From %c to %c\n",from,to);
    else
    {
        hanoi(x-1,from,aux,to);
        printf("Move Disk From %c to %c\n",from,to);
        hanoi(x-1,aux,to,from);
    }
}

void main( )
{
    int disk;
    int moves;
    clrscr();
    printf("Enter the number of disks you want to play with:");
    scanf("%d",&disk);
    moves=pow(2,disk)-1;
    printf("\nThe No of moves required is=%d \n",moves);
    hanoi(disk,'A','C','B');
    getch( );
}


Output:
Enter the number of disks you want to play with: 3

The No of moves required is=7
Move Disk from A to C
Move Disk from A to B
Move Disk from C to B
Move Disk from A to C
Move Disk from B to A
Move Disk from B to C
Move Disk from A to C

Write a C program to find the Square root of a given number

#include 
#include 
main()
{
      int a;
      clrscr();
      printf("ENTER ANY NUMBER\n");
      scanf("%d",&a);
      printf("SQUARE ROOT OF %d IS %4.3f\n",a,(float)sqrt(a));
    getch();
}

Write a C program to find the area and circumference of a circle

#include
int main()
{
int rad;
float PI=3.14,area,ci;

printf("nEnter radius of circle: ");
scanf("%d",&rad);

area = PI * rad * rad;
printf("nArea of circle : %f ",area);

ci = 2 * PI * rad;
printf("nCircumference : %f ",ci);

return(0);
}

Output:
Enter radius of a circle : 1
Area of circle : 3.14
Circumference  : 6.28

Write a C program for counting the number of words, lines, special characters in a given text

#include
#include
#include
#include

/*low implies that position of pointer is within a word*/
#define low 1 
/*high implies that position of pointer is out of word.*/
#define high 0 

void main()
{
int nob,now,nod,nov,nos,pos=high;
char *s;
nob=now=nod=nov=nos=0;
clrscr();

printf("Enter any string:");
gets(s);

while(*s!='')
{
if(*s==' ')  /* counting number of blank spaces. */
    {
    pos=high;
    ++nob;
    }
else if(pos==high) /* counting number of words. */
    {
    pos=low;
    ++now;
    }

if(isdigit(*s))   /* counting number of digits. */
    ++nod;
if(isalpha(*s))    /* counting number of vowels */
    switch(*s)
        {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
        case 'A':
        case 'E':
        case 'I':
        case 'O':
        case 'U':
        ++nov;
        break;
        }

/* counting number of special characters */
if(!isdigit(*s)&&!isalpha(*s))
    ++nos;

s++;
}

printf("nNumber of words %d",now);
printf("nNumber of spaces %d",nob);
printf("nNumber of vowels %d",nov);
printf("nNumber of digits %d",nod);
printf("nNumber of special characters %d",nos);

getch();
}

Write a c program to find the roots of a quadratic equation

#include
#include
int main(){
    int a,b,c;
    double x,y,d;

    printf("Enter a , b , c of quadratic equation: ");
    scanf("%d%d%d",&a,&b,&c);

    //calculating the value of d
    d = sqrt(b * b - 4 * a * c);

    //Checking real solution is possible or not
    if(d<0){
         printf("Real number root is not possible");
         exit(1);
    }
    //finding the root of quadractic equation
    x = (-b + d) / 2 * a;
    y = (-b - d) / 2 * a;

    //printing the root of the quadractic equation
    printf("Solution of quadratic equation are %lf , %lf",x,y);

   
    return 0;
}

Write a C program to convert the digits into words

Input: 123 Output: one hundred twenty three
#include 
#include 
#include 
void main(){
    char init[27][12] = {" one "," two "," three ",
                " four "," five "," six ",
                " seven "," eight "," nine ",
                " ten "," eleven "," twelve ",
                " thirteen "," fourteen "," fifteen ",
                " sixteen "," seventeen "," eighteen ",
                " nineteen "," twenty "," thirty ",
                " fourty "," fifty "," sixty ",
                " seventy "," eight "," ninty "};
    char sthou[20]="",shund[20]="",sval1[20]="",sval2[20]="",result[100]="";
    int thou=0,hund=0,ten=0,temp=0,val1,val2,num,rem,c=0;

clrscr();
//USING COBOL LOGIC
     printf("*****AMOUNT IN WORDS*****\n\n");
     printf("Enter any value (upto 4 digits) : ");
     scanf("%d",&num);
     while(num>0){
         rem = num%10;
         c++;
         if(c<=2)
        temp = temp * 10  +rem;
         elseif(c==3)
        hund = rem;
         elseif(c==4)
        thou = rem;
         num = num/10;
     }
     while(temp>0){  //as ten contains two digit so reverse it
        rem = temp%10;
        ten = ten * 10 + rem;
        temp= temp/10;
     }

     if(thou>0){
       strcpy(sthou,init[thou-1]);
       strcat(sthou," thousand ");
       strcat(result,sthou);
     }

     if(hund>0){
       strcpy(shund,init[hund-1]);
       strcat(shund," hundred ");
       strcat(result,shund);
     }

     if(ten>0){
          if(ten>20){
          val1 = ten/10;
          val2 = ten%10;
          }
          if(val1>0){
           strcpy(sval1,init[val1+(18-1)]);
           strcat(result,sval1);
          }
          if(val2>0){
           strcpy(sval2,init[val2-1]);
           strcat(result,sval2);
          }
     }
     printf("\n\nAmount in word is as under \n");
     printf("%s",result);

getch();
}

Write a C Program convert from any base to any other base.

/*
 * Convert from any base to any other base.
 */
#include 
#include 
#include 
#include 

#define  MINBASE   2u               /* smallest base */
#define  MAXBASE  36u               /* largest base */

int main()
{
  void displayValueAndBases(unsigned long num, int base, int newbase);
  long getNumberInBaseN(unsigned int b);
  int  getBase(unsigned int minbase, unsigned int maxbase);

  int  base;                        /* initial base */
  int  newbase;                     /* final base*/
  unsigned long num;                /* initial value, in base 10 */

  printf("Enter initial base: ");   /* grab initial base (in base 10) */
  if ((base = getBase(MINBASE, MAXBASE)) != -1)
  {                                
    printf("Enter target base: ");             /* grab target base */
    if ((newbase = getBase(MINBASE, MAXBASE)) != -1)
    {
      printf("Enter number to convert: ");     /* grab number */
      while ((num = getNumberInBaseN(base)) != -1)
      {                             
        displayValueAndBases(num, base, newbase);
        printf("Enter another base %i number to convert: ", base);
      }
      putchar('\n');
    }
  }

  return EXIT_SUCCESS;
}


void displayValueAndBases(unsigned long num, int base, int newbase)
{
  void displayValueInBase(unsigned long v, unsigned int b);

  displayValueInBase(num, base);
  printf(" in base %i is ", base);
  displayValueInBase(num, newbase);
  printf(" in base %i.\n", newbase);
}


/*
 * Read in the base using getNumberInBaseN
 */

int getBase(unsigned int minbase, unsigned int maxbase)
{
  long getNumberInBaseN(unsigned int b);

  long base;

  if ((base = getNumberInBaseN(10)) == -1)
    printf("Error: nonnumeric base detected\n");
  else
  {
    if (base < minbase)             /* set to -1 if too small */
    {
      printf("Error: Smallest base is %u.\n", minbase);
      base = -1;
    }
    if (base > maxbase)             /* set to -1 if too large */
    {
      printf("Error: Largest base is %u.\n", maxbase);
      base = -1;
    }
  }
  return (int) base;                /* base is in range of int */
}



/*
 * Read a base N number, one character at a time.
 */
              
long getNumberInBaseN(unsigned int base)
{
  int  toDecimal(int c, int b);

  int  c;                          /* next input character */
  int  value;                      /* decimal value of next char */
  long sum;                        /* running total */

  sum = -1;
  if ((c = getchar()) != EOF)      /* EOF is error */
  {                       
    if ((value = toDecimal(c, base)) != -1)           
    {                              /* within number, compute sum */
      sum = 0;
      while (value != -1)        
      {                            /* valid next digit in base */
        sum = base * sum + value;  /* update number */
        c = getchar();
        value = toDecimal(c, base);
      }
    }
    if (c != '\n')             
    {
      sum = -1;                    /* indicate error! */
      while (c != '\n')            /* skip rest of line */
        c = getchar();   
    }
  }
  return sum;
}


/*
 * Functions to convert digits to and from characters (ASCII ONLY).
 *   toDecimal - convert char to equivalent decimal number.
 *   toChar - convert decimal number to equivalent character.
 */

int toDecimal(int c, int base) 
{
  int value;

  if (isdigit(c))               /* set value if the input is anything */
    value = c - '0';            /* we know how to handle */
  else
    if (islower(c))
      value = c - 'a' + 10;
    else 
      if (isupper(c))
        value = c - 'A' + 10;
      else                      /* if not, it's an error */
        value = -1;

  if (value >= base)            /* make sure it's legal for base */
    value = -1;

  return value;
}

int toChar(int value)          
{                       
  int c;

  if (value < 10)
    c = '0' + value;
  else
    c = 'A' + value - 10;
  return c;
}



/*
 * Display a value in a specified base between 2 and 36.
 */

void displayValueInBase(unsigned long v, unsigned int b)
{
  int toChar(int value);           /* Addition to Chapter 4 */

  unsigned int k;                  /* digits needed in result */
  unsigned long divisor;           /* initially b^(# of digits - 1) */

  if (v == 0)                      /* zero is the same in any base */
    printf("0");
  else
  {
    k = floor(log10(v)/log10(b)) + 1;
    divisor = pow(b, k - 1);       /* first divisor: b^(k - 1) */

    /* Run through value, calculating and displaying the value of each
       of the digits in the new base (left to right) */

    while (divisor >= 1)      
    {
      putchar(toChar((int)(v / divisor)));  /* Change from Chapter 4 */
      v = v % divisor;
      divisor = divisor / b;
    }
  }
}

Write a C program to find the sum of N Natural numbers

/* This program is solved using while loop. */
int main()
{
    int n, count, sum=0;
    printf("Enter an integer: ");
    scanf("%d",&n);
    count=1;
    while(count<=n)       /* while loop terminates if count>n */
    {
        sum+=count;       /* sum=sum+count */
        ++count;
    }
    printf("Sum = %d",sum);
    return 0;
}
/* This program is solve using for loop. */
int main()
{
    int n, count, sum=0;
    printf("Enter an integer: ");
    scanf("%d",&n);
    for(count=1;count<=n;++count)  /* for loop terminates if count>n */
    {
        sum+=count;                /* sum=sum+count */
    }
    printf("Sum = %d",sum);
    return 0;
}

Output:
Enter an integer: 100
Sum = 5050

Write a C program to find the GCD of two integer values.

Greatest common divisor (gcd), also known as the greatest common factor (gcf), or highest common factor (hcf), of two or more integers (at least one of which is not zero), is the largest positive integer that divides the numbers without a remainder. For example, the GCD of 8 and 12 is 4. Procedure 1:
int main(){

    int x,y,m,i;

    printf("Insert any two number: ");

    scanf("%d%d",&x,&y);
    if(x>y)
         m=y;
    else
         m=x;

    for(i=m;i>=1;i--){
         if(x%i==0&&y%i==0){
             printf("\nHCF of two number is : %d",i) ;
             break;
         }
    }
    return 0;
}
Procedure 2:
int main()
{
     int n1,n2;
     printf("\nEnter two numbers:");
     scanf("%d %d",&n1,&n2);
     while(n1!=n2)
     {
         if(n1>=n2-1)
              n1=n1-n2;
         else
              n2=n2-n1;
     }
     printf("\nGCD=%d",n1);
   return 0;
}

Write a c program to find largest among three numbers

Using Conditional Operators:
int main()
{
  int a,b,c,Max;
  printf("\nEnter 3 numbers:");
  scanf("%d %d %d",&a,&b,&c);

  Max=(a>b&&a>c?a:b>c?b:c);
  printf("\nThe biggest number is: %d",Max);

  return 0;
}

Write a C program to convert the given temperature from Centigrade to Fahrenheit

The formula to convert Centigrade to Fahrenheit is - F = 1.8 * C + 32

void main() 
{ 
 float c, f ; 
 clrscr() ; 
 printf("Enter the centigrade : ") ; 
 scanf("%f", &c) ; 
 f = (1.8 * c + 32) ; 
 printf("\nThe farenheit is : %.2f", f) ; 
 getch() ; 
} 
Output:
Enter the centigrade : 50
The farenheit is : 122.00 
The formula for Fahrenheit to Centigrade conversion is - C = (F - 32) / 1.8
void main() 
{ 
 float c, f ; 
 clrscr() ; 
 printf("Enter the fahrenheit : ") ; 
 scanf("%f", &f) ; 
 c = (f - 32) / 1.8 ; 
 printf("\nThe centigrade is : %.2f", c) ; 
 getch() ; 
} 
Output:
Enter the fahrenheit : 122
The centigrade is : 50.00 

Write a C program whether the given number is Armstrong number or not.

Armstrong number:

Those Numbers which sum of its digits to power of number of its digits is equal to that numbers are known as Armstrong Numbers.

Example 1: 153 Total Digits in 153 is 3 
               1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 

Example 2: 1634 Total digits in 1634 is 4 
                1^4 + 6^4 + 3^4 +4^4 = 1 + 1296 + 81 + 64 =1634 

Examples of Armstrong numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084, 548834, 1741725
int main(){
    int num,r,sum=0,temp;

    printf("Enter a number: ");
    scanf("%d",&num);

    temp=num;
    while(num!=0)
    {
         r=num%10;
         num=num/10;
         sum=sum+(r*r*r);
    }
    if(sum==temp)
         printf("%d is an Armstrong number",temp);
    else
         printf("%d is not an Armstrong number",temp);

    return 0;
}

Out Put:
Enter a number: 153
153 is an Armstrong number

Write a C program to demonstrate call by value and call by reference.

Call By Value & Call By Reference:
void callByValue(int, int);
void callByReference(int *, int *);
 
int main()
{
    int x=30, y=40;
    clrscr();
    printf("Value of x = %d and y = %d.\n", x,y);
 
    callByValue(x, y);
    printf("\nCall By Value function call...\n");
    printf("Value of x = %d and y = %d.\n", x,y);
 
    callByReference(&x, &y);
    printf("\nCall By Reference function call...\n");
    printf("Value of x = %d and y = %d.\n", x,y);
 
    getch();
    return 0;
}
 
void callByValue(int x, int y)
{
    int temp;
    temp = x;
    x = y;
    y = temp;
}
 
void callByReference(int *x, int *y)
{
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

OUTPUT:
      Values of x = 30 and and y=40.
      Call By Value function call... 
      Values of x = 30 and and y=40.
      Call By Reference function call...
      Values of x = 40 and and y=30.

Write a C program to calculate the total and average of marks

void main( )
{
      int avg, sum = 0;
      int marks[10];
      for (int i = 0; i<=9; i++ )
      {
            printf ( “\n Please enter marks for 10 students: ” );
            scanf ( “%d”, &marks[i] );
      }
     for (i = 0; i<=9; i++)
          sum = sum + marks[i];
     avg = sum / 20;
     printf ( “\n Total marks secured by 10 students in a test are %d”, sum);
     printf ( “\n Average marks secured by 10 students in a test are %d”, avg);

}

Android Multimedia: CODECS

The word CODEC means Encoder + Decoder.


A codec is a way of compressing and decompressing digital files. Each codec uses a slightly different set of algorithms to accomplish this. 

Multimedia data is compressed or encoded by encoders and decompressed or decoded by decoders.

Traditionally a codec is a software algorithm/module runs on a computing device. Sometimes Digital Signal Processors (DSP) are used for realizing faster codec algorithms.

Software algorithms are in-adequate to handle today’s challenging system demands in terms of data rate, video resolution, sampling rate etc.

Today most of the multimedia systems use HW accelerated Codecs. HW accelerators are dedicated HW module inside a processor for faster multimedia data processing



Examples of speech codecs 
  • G723, G729 used for VOIP and video conferencing 
  • AMR-NB used in GSM & UMTS networks and systems those record voice 
  • AMR-WB, AMR-WB+ used in CDMA networks 
Examples of Audio codecs 

  • MP3 – Used in all systems those can play music 
  • AAC - Used in most of the systems those can play music & record 
  • WMA – Microsoft’s proprietary codec used in many systems 
  • RA – Real audio used by Real Networks. 
Examples of Video codecs 
  • MPEG1 – Used in Video CD
  • MPEG2 – Used in DVD 
  • MPEG4, H264 – Used in computer, handheld devices, digital TV transmission 
  • WMV - Microsoft’s proprietary codec used in many systems 
  • RV – Real video used by Real Networks 
Examples of image codecs 

  • JPEG, JPEG 2000, PNG, GIF

Write C Program to check whether a given year is a leap year or not

Definition of leap year:

Rule 1: A year is called leap year if it is divisible by 400.
For example: 1600, 2000 etc leap year while 1500, 1700 are not leap year.


Rule 2: If year is not divisible by 400 as well as 100 but it is divisible by 4 then that year are also leap year.
For example: 2004, 2008, 1012 are leap year.


Leap year logic or Algorithm of leap year or Condition for leap year:

IF year MODULER 400 IS 0
      THEN leap_year
ELSE IF year MODULER 100 IS 0
      THEN not_leap_year
ELSE IF year MODULER 4 IS 0
      THEN leap_year
ELSE
      not_leap_year


int main(){
    int year;

    printf("Enter any year: ");
    scanf("%d",&year);

    if(((year%4==0)&&(year%100!=0))||(year%400==0))
         printf("%d is a leap year",year);
    else
         printf("%d is not a leap year",year);
  
    return 0;
}

Output:
Enter any year: 2008
2008 is a leap year

Write a C program to find the largest of 3 numbers.

Procedure 1:
int main() 
{
   int a, b, c;
   printf("Enter the value for a:\n");
   scanf("%d", &a);
   printf("Enter the value for b:\n");
   scanf("%d", &b);
   printf("Enter the value for c:\n");
   scanf("%d", &c);
   
   if ((a > b) && (a > c)) 
   {
      printf("\n The big one is a= %d", a);
   } 
   else if (b > c) 
   {
      printf("\n The big one is b= %d", b);
   } 
   else 
   {
      printf("\n The big one is c= %d", c);
   }
   return 0;
}
Procedure 2:
void main()
{
 
   int a,b,c;
   clrscr();
   printf("Enter the value of a:");
   scanf("%d",&a);
   printf("\nEnter the value of b:");
   scanf("%d",&b);
   printf("\nEnter the value of c:");
   scanf("%d",&c);
   
   if(a>b)
   {
      if(a>c)
          printf("a is largest");
      else
          printf("c is largest");
   }
   else
   {
       if(b>c)
          printf("b is largest");
       else
          printf("c is largest");
   }
getch();
}
Using Functions:
int function(int x,int y,int z)
{
    if(x>y && x>z)
            return x;
    else if(y>z)
            return y;
    else
            return z;
}
void main()
{
int a=10,b=39,c=30;
int res;
res=function(a,b,c);
printf("Res %d:",res);
}
Using Conditional Operator:
int main()
{
  int a,b,c,big;
  printf("\nEnter 3 numbers:");
  scanf("%d %d %d",&a,&b,&c);

  big=(a>b&&a>c?a:b>c?b:c);
  printf("\nThe biggest number is: %d",big);

  return 0;
}