Thursday 29 March 2012

A to Z of C


A to Z of C
“A to Z of C”, by R. Rajesh Jeba Anbiah & K. Joseph Wesley, is an evolving non-profit book on C/DOS/Turbo C programming. Each chapter of this book can be downloaded in pdf format.
Contents
  • ANSI C
  • DOS Programming
  • Advanced Graphics Programming
  • Advanced Programming
  • Mathematics & C
  • Algorithms & C
  • Illegal Codes
  • Next Step
  • Smart Dictionary
  • Postlude
Book Details
Author(s): R. Rajesh Jeba Anbiah & K. Joseph Wesley
Format(s): PDF
Link: Download.

Wednesday 28 March 2012


To calculate perimeter & area of a rectangle




To accept the length,breadth of rectangle and to display its perimeter and area

#include<stdio.h>
Void main()
{
Float length,breadth,perimeter,area;
Clrscr();
Printf(“enter the dimension of a rectangle\n”);
Printf(“length ?”);
Scanf(“%f”,&length);
Printf(“breadth ?”);
Scanf(“%f”,&breadth);
Perimeter=2*(length+breadth);
area=length*breadth;
printf(“perimeter of the rectangle is %.3g\n”,perimeter);
printf(“area of the rectangle is % .3g”,area);
getch();



TO CHECK WHETHER A GIVEN NUMBER IS PERFECT FACTORIAL OR NOT




#include<stdio.h>
Void main()
{
Int n,i=1,flag=0;
Long fact=1;
Printf(“enter your number:”);
Scanf(“%d”,&n);
For(;fact<=n;++,fact*=i)
If(fact==n)
{
Flag=1;
Break;
}
If(flag)
Printf(“%d is perfect factorial”,n);
Else
Printf(“%d is not a perfect factorial”,n);
Getch();
}


TO CONVERT A LOWER CASE TEXT TO UPPERCASE




#include<stdio.h>
Void main()
{
Int count=0;
Char text[80];
Clrscr();
Text[count]=getchar();
While(text[count]!=’\n’)
{
Count++;
Text[count]=getchar();
}
Count=0;
While(text[count]!=’\n’)
{
Putchar(toupper(text[count]));
Count++;
}
Getch();



TO CONVERT NUMBER OF DAYS INTO YEARS, WEEKS AND DAYS




TO convert a given number of days into to a measure of time given in years weeks and days
#include<stdio.h>
Void main();
{
Int temp,days,week, year,day;
Printf(“enter the number of days:”);
Scanf(“%d”,&days);
Temp=days;
Year=(int)days/365;
Days=days%10;
Week=(int)days/7;
Days=days%7;
Printf(“%d days equals %d year,%d week and %d days”,temp,year,week,day);
Getch();
}


TO CONVERT TEMPERATURE IN DEGREE CELSIUS TO FAHRENHEIT




To accept a temperature in degree Celsius(c) and to display it in degree fahrenheit(f) using the formula f=9.0/5.0*c+32
#include<stdio.h>
Void main()
{
float Celsius,fahrenheit;
clrscr();
printf(“enter temperature in degree Celsius:”);
scanf(“%f”,&celsius);
Fahrenheit=(9.0/5)*Celsius+32;
printf(“%g degree Celsius is %g fahrenheit”,elsius,fahrenheit);
Getch();
}




TO DISPLAY AMSTRONG NUMBERS UP TO A GIVEN NUMBER




#include<stdio.h>
#include<math.h>
Void main()
{
Int sum,num,n,digit,temp;
Clrscr();
Printf(“up to which number ?”);
Scanf(“%d”&n);
Printf(“amstong numbers up to %d are:\n”);
For(num=1;num<=n;+}+num)
{
For(temp=num,sum=0;temp>0;temp/=10)
{
Digit=temp%10;
Sum+=pow(digit,3);
}
If(num==sum)
Printf(“%d\t”,num);
}
Getch();
}


TO DISPLAY EVEN AND ODD NUMBERS WITHIN A RANGE SEPERATELY ALSO DISPLAY THEIR SUM AND AVERAGE




#include<stdio.h>
Void main()
{
Int lower,upper,even,odd,count,temp;
Float evensum=0.0,oddsum=0.0,evenavg,oddavg;
Clrscr();
Printf(“enter the lower bound:”);
Scanf(“%d”,&lower);
Printf(“enter the upper bound:”);
Scanf(“%d”,&upper);
If(lower>upper)
{
Temp=lower;
Lower=upper;
Upper=temp;
}
If(lower%2==0)
Even=lower+2;
Else
Even=lower+1;
Printf(“even numbers between %d and %d are :\n”,lower,upper);
For(count=0;even<upper;even+=2,++count)
{
Printf(“%d\t”,even);
Evensum+=even;
}
Evenavg=avensum/count;
Printf(“sum of the even numbers from %d to %d is %g”,lower,upper,evensum);
Printf(“average of the even numbers from %d to %d is %g\n\n”,lower,upper,evenavg);
if(lower%2=1)
odd=lower+2;
else
odd=lower+1;
printf(“odd numbers from %d to %d are\n”,lower,upper);
for(count=0;odd<upper;odd+=2,++count)
{
Printf(“%d\t”,odd);
Oddsum+=odd;
}
Oddavg=oddsum/count;
Printf(“\nsum of the odd numbers from %d to %d is %g”,lower,upper,oddsum);
Printf(“\naverage of the odd numbers from %d to %d is %g”,lower,upper,oddavg);
Getch();
}


TO DISPLAY THE FIRST ‘N’ RPIME NUMBERS




#include<stdio.h>
#include<math.h>
Void main()
{
Int num,i,n,flag,count=0;
Clrscr();
Printf(“how many prime number ?”);
Scanf(“%d”,&n);
Printf(“first %d prime numbers are :\n”,n);
For(num=2;count<=n;++num)
{
Flag=1;
For(i=2;i<=sqrt(num);++i)
{
if(num%i==0)
{flag=0;
Break;
}
If(flag)
{
Printf(“%d\t”,num);
++count;
}
}
getch();
}


TO DISPLAY THE MULTIPLES OF 5 WITHIN A GIVEN RANGE BOTH THE UPPER & LOWER BOUNDA ARE EXCLUDED




#include<stdio.h>
Void main()
{
Int lower,upper,temp;
Printf(“enter lower bound”);
Scanf(“%d”,&lower);
Printf(“enter upper bound”);
Scanf(“%d”,&upper);
If(lower>upper)
{
Temp=upper;
Upper=lower;
Lower=temp;
}
Printf(“the multiples of 5 between %d and %d are:”,lower,upper);
If(lower%5=0)
Lower=lower+5;
Else
Lower=lower+(5-(lower%5));
For(;lower<upper;lower+=5)
Printf(“%d\t”,lower);
Getch();
}

Data Structures and Algorithm Analysis by Clifford A. Shaffer


Third edition of “Data Structures and Algorithm Analysis in C++” by Dr. Clifford A. Shaffer is available in pdf format for free. This book describes many techniques for representing data.
Description
A comprehensive treatment focusing on the creation of efficient data structures and algorithms, this text explains how to select or design the data structure best suited to specific problems. It uses C++ as the programming language and is suitable for second-year data structure courses and computer science courses in algorithmic analysis.
Contents
  • Data Structures and Algorithms
  • Mathematical Preliminaries
  • Algorithm Analysis
  • Lists, Stacks, and Queues
  • Binary Trees
  • Non-Binary Trees
  • Internal Sorting
  • File Processing and External Sorting
  • Searching
  • Indexing
  • Graphs
  • Lists and Arrays Revisited
  • Advanced Tree Structures
  • Analysis Techniques
  • Lower Bounds
  • Patterns of Algorithms
  • Limits to Computation


Book Details
Author(s): Clifford A. Shaffer
Format(s): PDF
File size: 2.56 MB
Number of pages: 613
Link: download

Tuesday 27 March 2012

#include<stdio.h>
#include<math.h>
main()
{
int i,j,k,r,a[10][10],b[10][10],sum=0,m;
printf("enter a 3/3 matrix\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 matrix is \n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("\t%d",a[i][j]);
b[i][j]=0;
}
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++;
}
sum=sum+pow(-1,i+1)*a[1][i]*(b[1][1]*b[2][2]-b[1][2]*b[2][1]);
}
printf("determinant of matrix is =%d  ",sum);
}

Friday 23 March 2012

how to transpose a metrix


#include<stdio.h>
main()
{
 int a[10][10],i,j,r,c;
 printf("enter the order of matrix");
 scanf("%d%d",&r,&c);
 printf("enter the elements");
 for(i=1;i<=r;i++)
 {
  for(j=1;j<=c;j++)
   scanf("%d",&a[i][j]);
 }
 printf("the transpose is \n");
 for(i=1;i<=c;i++)
 {
  for(j=1;j<=r;j++)
  {
   printf(" %d",a[j][i]);
  }

 printf("\n");
}
}

Thursday 15 March 2012


TO DISPLAY THE SUM OF INDIVIDAL DIGITS OF A FOUR DIGIT NUMBER




To accept a four digit number and to display the sum of individual digits
#include<stdio.h>
Viod main()
{
Int number,temp,d1,d2,d3,d4,sum;
Clrscr();
Printf(“enter a number”;
Scanf(“%d”,&number);
Temp=number;
D4=number/1000;
Number=number%1000;
D3=number/100;
Number=number%100;
D2=number/10;
D1=number%10;
Sum=d4+d3+d2+d1;
Printf(“sum of individual digits of %d is %d”,temp sum);
Getch();
}

how convert decimal number to hexadecimal number

#include<stdio.h>
main()
{
int i=0,j,n,a[20],m;
char b[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
printf("enter the decimal number:");
scanf("%d",&n);
m=n;
while(n>0)
{
a[i]=n%16;
n=n/16;
i=i++;
}
printf("hexadecimal equal of %d is =",m);
for(j=i-1;j>=0;j--)
{
printf("%c",b[a[j]]);
}
}

how calculate square root of a number

#include<stdio.h>
float root(float num);
void main()
{
float n,ans;
printf("enter the number:");
scanf("%f",&n);
ans=root(n);
printf("square root of %f=%f",n,ans);
}
float root(float num)
{
if(num>=0)
{
float x=num;
int i;
for(i=0;i<20;i++)
{
x=(((x*x)+num)/(2*x));
}
return x;
}
}

how convert decimal number to hexadecimal number with or without floating point

#include<stdio.h>
main()
{
int i=0,j,a[20],m,c[20],g,f;
char b[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
float n,e;
printf("enter the decimal number with or without fraction:");
scanf("%f",&n);
m=(int)n;
e=n-m;
while(m>0)
{
a[i]=m%16;
m=m/16;
i=i++;
}
for(f=0;f<=6;f++)
{
e=e*16.0;
c[f]=e;
e=e-c[f];
}
printf("hexadecimal equal\n");
for(j=i-1;j>=0;j--)
{
printf("%c",b[a[j]]);
}
printf(".");
for(g=0;g<f;g++)
printf("%c",b[c[g]]);

}