Thursday 26 April 2012

GNU C Programming

This book is a tutorial for the computer programming language C. The authors of this book hope you will learn everything you need to write simple C programs from this book.
Description
To get the most from this book, you should have some basic computer literacy — you should be able to run a program, edit a text file, and so on. You should also have access to a computer running a GNU system such as GNU/Linux.
The tutorial introduces basic ideas in a logical order and progresses steadily. You do not need to follow the order of the chapters rigorously, but if you are a beginner to C, it is recommended that you do. Later, you can return to this book and copy C code from it; the many examples range from tiny programs that illustrate the use of one simple feature, to complete applications that fill several pages. Along the way, there are also brief discussions of the philosophy behind C.
Contents
  • Using a compiler
  • The form of a C program
  • Functions
  • Variables and declarations
  • Scope
  • Expressions and operators
  • Parameters
  • Pointers
  • Decisions
  • Loops
  • Preprocessor directives
  • Libraries
  • Arrays
  • Strings
  • Input and output
  • Putting a program together
  • Advanced operators
  • More data types
  • Data structures
  • Recursion
  • Style
  • Debugging
  • Example programs
  • A note from the original author
  • Reserved words in C
  • Precedence of operators
  • Special characters
  • Character conversion table
  • A word about goto
Book Details
Author(s): Mark Burgess and Ron Hale-Evans
Format(s): PDF, PostScript, DVI, Texinfo
File size: 1.37 MB
Number of pages: 290
Link :download

TO FIND GCD AND LCM FROM A SET OF NUMBERS

/* program to find the gcd and lcm */

#include<stdio.h>
#include<math.h>
 main()
{
    int a[10],n,i,j,c,max,min,more;
    unsigned long prod;
   
    printf("enter the no of entries: ");
    scanf("%d",&n);
    printf("enter the entries: ");
    for(i=0;i<n;i++)
    {
        scanf("%d",&c);
        if(c>0)
        a[i]=c;
        else
        {
            printf("invalid number ");
            return;
        }
    }
        max=a[0];
        for(i=0;i<n;i++)
        if(a[i]>=more)
        max=a[i];
        min=a[0];
        for(i=0;i<n;i++)
    if(a[i]<min)
    min=a[i];
    for(i=0,prod=1;i<n;i++)
    prod=prod*a[i];
    for(i=max;i<=prod;i+=max)
    {
        c=0;
        for(j=0;j<n;j++)
        if(i%a[j]==0)
        c+=1;
        if(c==n)
        {
            printf("\nthe lcm of the numbers= %d",i);
            break;
        }
    }
    for(i=min;i>0;i--)
    {
        if (min %i==0)
        {
            c=0;
            for(j=0;j<n;j++)
            if(a[j] %i ==0)
            c+=1;
        }
        if(c==n)
        {
            printf("\nthe gcd of the numbers=%d",i);
            break;
        }
    }
       
}

To find cose(x),sine(x),e^x of a number

#include<stdio.h>
main()
{
int n,x,y;
double z,ts,tc,ss,sc,pi,xy,xz;
pi=3.141592654;
printf("enter the angle");
scanf("%d",&x);
z=x*(pi/180);
ss=z;
sc=1;
ts=z;
tc=1;
xy=1;
xz=1;
for(n=1;n<=1000;n++)
  {
ts=-1*ts*z*z/(2*n*(2*n+1));
ss=ss+ts;
tc=-1*tc*z*z/(2*n*(2*n-1));
sc=sc+tc;
xy=xy*x/n;
xz=xz+xy;
}
printf("sin(%d)=%f\n",x,ss);
printf("cos(%d)=%f\n",x,sc);
printf("exponential of %d(e^%d)= %f\n",x,x,xz);
}

menu driven mean, mode and median

#include<stdio.h>
main()
{
int i,j,count=0,m=0,c,n;
float mode,median,a[20],sum=0.0,temp,mean;
printf("enter the limite:");
scanf("%d",&n);
printf("enter your numbers:\n");
for(i=1;i<=n;i++)
{
scanf("%f",&a[i]);
sum=sum+a[i];
}

mean=sum/n;
for(i=1;i<=n-1;i++)
for(j=i+1;j<=n;j++)
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
printf("enter your choice\n");
printf("enter 1 for mean\n");
printf("enter 2 for median\n");
printf("enter 3 for mode\n");
printf("enter 4 fo mean,median and mode\n");
scanf("%d",&c);
if(c==1||c==4)
printf("mean=%f",mean);
if(c==2||c==4)
{
if(n%2==0)
median=(a[n/2]+a[n/2+1])/2.0;
else

median=a[(n+1)/2];

printf("\nmedian=%f",median);
}
if(c==3||c==4)
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(a[i]==a[j])
count++;
}
if(m<count)
{
m=count;
mode=a[i];
}
count=0;
}
printf("\nmode=%f",mode);
for(i=1;i<=n;i++)
{
for(j=i;j<=n;j++)
{
if(a[i]==a[j])
count++;
}
if(m==count)
{
if(a[i]!=mode)
printf("\t%f ",a[i]);
}
count=0;
}
}
}

Tuesday 10 April 2012

Image Processing in C: Analyzing and Enhancing Digital Images


Image Processing in C: Analyzing and Enhancing Digital Images
This book is a tutorial on image processing. Each chapter explains basic concepts with words and figures, shows image processing results with photographs, and implements the operations in C. Explains the basic concepts of analyzing and enhancing digital images. Author has distilled image processing down to its essentials and clearly explains how to do it.
Description
The C code in this book is based on a series of articles published in The C Users Journal from 1990 through 1993, and includes three entirely new chapters and six new appendices. The new chapters are 1) an introduction to the entire system, 2) a set of routines for Boolean operations on images — such as subtracting or adding one with another, 3) a batch system for performing offline processing (such as overnight for long involved manipulations). The C Image Processing System (CIPS) works with Tag Image File Format (TIFF) gray scale images. The entire system has been updated from the original publications to comply with the TIFF 6.0 specification from June 1993 (the magazine articles were written for the TIFF 5.0 specification.) The text and accompanying source code provide working edge detectors, filters, and histogram equalizers, I/O routines, display and print procedures that are ready to use, or can be modified for special applications. Print routines are provided for laser printers, graphics printers, and character printers. Display procedures are provided for monochrome, CGA, VGA, and EGA monitors. All of these functions are provided in a system that will run on a “garden variety” PC, not requiring a math co-processor, frame grabber, or Super VGA monitor.
Contents
  • Introduction to CIPS
  • Image File Input and Output
  • Viewing and Printing Image Numbers
  • Halftoning
  • Histograms and Equalization
  • Basic Edge Detection
  • Advanced Edge Detection
  • Spatial Frequency Filtering
  • Image Operations
  • Histogram-Based Segmentation
  • Segmentation via Edges & Gray Shades
  • Manipulating Shapes
  • Boolean and Overlay Operations
  • Geometric Operations
  • Warping and Morphing
  • Basic Textures Operations
  • Random Dot Stereograms
  • Steganography: Hiding Information
  • Command-Line Programming
  • A Tcl/Tk Windows Interface
Book Details
Author(s): Dwayne Phillips
Format(s): PDF
File size: 9.21 MB
Number of pages: 816
link:download

Learning Cocoa with Objective-C


Learning Cocoa with Objective-C
Free C book from O’Reilly Commons. Learning Cocoa with Objective-C is the “must-have” book for people who want to develop applications for Mac OS X, and is the only book approved and reviewed by Apple engineers.
Description
Based on the Jaguar release of Mac OS X 10.2, this edition of “Learning Cocoa” includes examples that use the Address Book and Universal Access APIs. Also included is a handy quick reference card, charting Cocoa’s Foundation and AppKit frameworks, along with an Appendix that includes a listing of resources essential to any Cocoa developer–beginning or advanced.
Contents
  • Introduction to Cocoa
  • Cocoa Development Tools
  • Object-Oriented Programming with Objective-C
  • The Cocoa Foundation Kit
  • Graphical User Interfaces
  • Windows, Views, and Controls
  • Custom Views
  • Event Handling
  • Models and Data Functionality
  • Multiple Document Architecture
  • Rich-Text Handling
  • Printing
  • Bundles and Resources
  • Localization
  • Defaults and Preferences
  • Accessory Windows
  • Finishing Touches
Book Details
Author(s): James Duncan Davidson
Format(s): HTML
Number of pages: 384
link:read online.

Free Online Book: Objective-C 2.0 Essentials


Free Online Book: Objective-C 2.0 Essentials
Free online book “Objective-C 2.0 Essentials”. The objective of this book is to teach the skills necessary to program in Objective-C using a style that is easy to follow, rich in examples and accessible to those who have never used Objective-C before.
Description
The objective of this book is to teach the skills necessary to program in Objective-C using a style that is easy to follow, rich in examples and accessible to those who have never used Objective-C before. Topics covered include the fundamentals of Objective-C such as variables, looping and flow control. Also included are details of object oriented programming, working with files and memory and the Objective-C Foundation framework.
Contents
  • The History of Objective-C
  • Installing Xcode and Compiling Objective-C on Mac OS X
  • Installing and using GNUstep and Objective-C on Windows
  • Installing and Using GNUstep and Objective-C on Linux
  • Building and Installing GNUstep on Linux
  • Objective-C 2.0 Data Types
  • Working with Variables and Constants in Objective-C
  • Objective-C Operators and Expressions
  • Objective-C 2.0 Operator Precedence
  • Commenting Objective-C Code
  • Objective-C Flow Control with if and else
  • The Objective-C switch Statement
  • Objective-C Looping – The for Statement
  • Objective-C Looping with do and while Statements
  • An Overview of Objective-C Object Oriented Programming
  • Writing Objective-C Class Methods
  • Objective-C – Data Encapsulation, Synthesized Accessors and Dot Notation
  • Objective-C Inheritance
  • Pointers and Indirection in Objective-C
  • Objective-C Dynamic Binding and Typing with the id Type
  • Objective-C Variable Scope and Storage Class
  • An Overview of Objective-C Functions
  • Objective-C Enumerators
  • An Overview of the Objective-C Foundation Framework
  • Working with String Objects in Objective-C
  • Understanding Objective-C Number Objects
  • Working with Objective-C Array Objects
  • Objective-C Dictionary Objects
  • Working with Directories in Objective-C
  • Working with Files in Objective-C
  • Constructing and Manipulating Paths with NSPathUtilities
  • Copying Objects in Objective-C
  • Using Objective-C Preprocessor Directives
Book Details
Author(s): Techotopia
Format(s): HTML
Number of pages: 208
link:read

to find permutation of string

#include<stdio.h>
#include<string.h>
main()
{
    int n,i,k=0;
    char a[50];
    void permu(char  a[50],int k,int n);
    printf("Enter the string:\n");
    gets(a);
    printf("permutation is:\n");
    n=strlen(a);
    permu(a,k,n);
}
void permu(char a[50],int k,int n)
        {
            char t,d[50];
            int i;
            if(k==n)
            {
                puts(a);
                return;
            }
            else
            {
               for(i=k;i<n;i++)
                {    
                t=a[i];
                a[i]=a[k];
                a[k]=t;
                strcpy(d,a);
                permu(d,k+1,n);
                 }
             }
        }
       
                   
   

to find the invers of a 3*3 matrix

this my creation and my logic.execute and comment it
#include<stdio.h>
#include<math.h>
main()
{
int i,j,k,r,a[10][10],b[10][10],c[10][10],det=0,m,h,flag=0,p=0;
printf("enter a 3/3 metrix\n");
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
{

printf("enter (%d of %d)\t ",i,j);
scanf("%d",&a[i][j]);
}
printf("your metrix A= \n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
printf("\t%d",a[i][j]);
printf("\n");
}
for(i=1;i<=3;i++)
{
for(j=2,m=1;j<=3;j++,m++)
for(r=1,k=1;k<=3;k++)
if(k!=i)
{
b[m][r]=a[j][k];
r++;
}
det=det+pow(-1,i+1)*a[1][i]*(b[1][1]*b[2][2]-b[1][2]*b[2][1]);

}

printf("determinant of matrix|A|=%d",det);
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
for(k=1,h=1;k<=3;k++)
{
for(m=1,flag=0,p=1;m<=3;m++)
{
if((k!=i)&&(m!=j))
{
b[h][p]=a[k][m];
p=p+1;
flag=1;
}
}
if(flag==1)
h++;
}
c[i][j]=pow((-1),i+j)*(b[1][1]*b[2][2]-b[1][2]*b[2][1]);
}

}

printf("\nco factor of a matrix=\n\n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
printf("\t%d",c[i][j]);
printf("\n");
}
printf("\ninverse of 3*3 matrix=adjoint of A/|A|=\n");
printf("\t...................\n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
printf("\t%d",c[j][i]);
printf("\n");
}

printf("\t...................\n");
printf("\t\t%d\n",det);
}

To find mode from the set of numbers

#include<stdio.h>
main()
{
    int a[10],i,j,count=0,mod,m=0,n;
    printf("Enter size of array:");
    scanf("%d",&n);
    printf("Enter values..");
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(a[i]==a[j])
               count++;
        }
        if(m<count)
        {
           m=count;
           mod =a[i];
        }
        count=0;
    }
    printf("Mode    : %d  ",mod);
    for(i=0;i<n;i++)
        {
                for(j=i;j<n;j++)
                {
                        if(a[i]==a[j])
                           count++;
                }

                if(m==count)
                {
                  if(a[i]!=mod)
                   printf("%d  ",a[i]);
                }
                count=0;
        }
   
}