Friday, 19 July 2013

Program to Print Even Number Between (1 to 10)

#include <stdio.h>
void main()
{
int a;
clrscr ();
printf("Enter the Value");
for (a=1;a<=10;++a)
{
if (a%2==0)
printf("\n%d",a);
}
getch();

}

Program to Print all Number Divided by 3 (1 to 50)

#include <stdio.h>
void main()
{
int a;
clrscr ();
printf("Enter the Value\n");
for (a=1;a<=50;++a)
{
if (a%3==0)
printf("\n%d",a);
}
getch();

}

Program to Implement Quick Sort

#include <stdio.h>
#include <conio.h>
void quicksort (int a[], int low, int high);
int partition(int a[], int low, int high);
int a[5] = {55, 1, 78, 13, 45};
void main( )
{
clrscr();
int i, n;
printf("\nOriginal array");
for(i=0; i < 5; i++)
printf("%4d", a[i]);
quicksort(a, 0, 4);
printf("\nThe sorted array is \n");
for(i=0; i < 5; i++)
printf("%4d", a[i]);
getch();
}
void quicksort (int a[], int low, int high)
{
int j;
if (low < high)
{
j = partition(a,low, high);
quicksort (a, low, j-1);
quicksort(a, j+1, high);
}
}
int partition(int a[], int low, int high)
{
int i, j, temp, key;
key = a[low];
i = low + 1;
j = high;
while (1)
{
while (i < high && key >= a[i])
i++;
while (key < a[j])
j--;
if (i < j)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
else
{
temp = a[low];
a[low] = a[j];
a[j] = temp;
}
return j;
}

}

Program in C to Implement Linear Search Techniques

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10], i, n, item, loc=-1;
clrscr();
printf(“Enter the number of element”);
scanf(“%d”,&n);
printf(“Enter the number\n”);
for(i=0; i<=n-1;i++)
{
scanf(“%d”,&a[i]);
}
printf(“Enter the number to be selected ”);
scanf(“%d”,&item);
for(i=0;i<=n-1;i++)
{
if(item==a[i])
{
loc=i;
break;
}
}
if(loc>=0)
printf(“\n%d is found in position %d”,item,loc+1);
else
printf(“\nItem does not exist”);
getch();

}

Algorithm for Binary Search

  1. Input an array A of an element an “data” to be sort
  2. LB=0,UB=n; mid = int((LB+UB)/2)
  3. Repeat Step 4 and 5 while(LB<=UB) and (A[Mid])!= data UB= mid-1
  4. If(data<A[mid])UB=mid-1ElseLB=mid+1
  5. Mid=int((LB+UB)/2)
  6. If(A[mid]==data)Printf(“The data is found”);ElsePrintf(“The data is not found”);
  7. Exit

Program in C to Implement Insertion Sort

#include<stdio.h>
#include<conio.h>
void main()
{
int i, j , n, temp,a[10];
clrscr();
printf(“Enter the size of array\n”);
scanf(“%d”,&n);
printf(“Enter %d elements \n”)
for(i=1;i<=n;i++)
{
scanf(%d”, &a[i]);
}
for(i=1;i<=n;i++)
{
temp=a[i];
j=i-1;
while((temp<a[j]&&(j>=0))
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=temp;
}
printf(“The sorted array is\n”);
for(i=1;i<=n;i++)
{
printf(“%d”,a[i]);
}
getch();

}

Algorithm for Linear Search

  1. Set data[n+1]=item
  2. Set loc=1
  3. Repeat while data[loc]=item
  4. Set loc=loc+1
  5. If loc=n+1, then set loc=0
  6. Exit

Algorithm for Deletion an Element in Queue

  1. If front=Rear=NULLThen print Underflow And Exit
  2. Item =Queue[Rear]
  3. If(Front=Rear=1)Then Set Front=0     Set Rear=0ElseFront= front+1
  4. Exit

Thursday, 18 July 2013

Algorithm for Insertion a Element in Queue

  1. If Front==1&&Rear==Max or Front=Rear+1Then print Overflow and Exit
  2. If Front=NullThen Set Front=Rear=1Else If Rear=Max thenSet Rear=1ElseRear=Rear+1
  3. Queue[Rear]=item
  4. Exit

Program in C to perform PUSH and POP on Stack

#include<stdio.h>
#include<conio.h>
void main()
{
int S[10],MAXSTK,TOP=0,item,n,i,D;
clrscr();
do
{
printf(“Enter the size\n”);
scanf(“%d”,&n);
printf(“Enter the choice \n1-Push \n2-Pop\n3-Display”);
scanf(“%d”,&n);
switch(n)
{
case 1:
{
if(TOP==MAXSTK)
{
printf(“Overflow”);
break;
}
else
{
printf(“Enter the item you want to insert ”);
scanf(“%d”,&item);
TOP=TOP+1;
S[TOP]=item;
break;
}
}
case 2:
{
if(TOP==0)
{
printf(“Underflow”);
}
else
{
item=S[TOP];
TOP=TOP-1;
printf(“Delete the item”,item);
bbreak;
}
}
case 3:
{
for(i=TOP;i>0;i--)
{
scanf(“%d”,S[i]);
break;
}
}
printf(“Enter 4 to continue\n”);
scanf(“%d”,&D);
}
while(D==4);
getch();

}

Algorithm for POP an Element from Stack

POP(S,MAXSTK,TOP,item)
  1. If TOP=NULL thePrint Underflow and Return
  2. Item =S[TOP]
  3. TOP=TOP-1
  4. Exit 

Algorithm for Pushing an Element into Stack

PUSH(s,MAXSTK,TOP,item)
  1. If TOP=MAXSTK thenPrint Overflow and Return
  2. TOP=TOP+1
  3. S[TOP]=item
  4. Exit

Program in C to Merge Two Arrays into Sorted Array

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],b[10],c[20],m,n,i,j,temp=0;
clrscr();
printf(“Entrer the size of array A\n”);
scanf(%d”,&m);
printf(“Enter the sorted element of Array A\n”);
for(i=0;i<m;i++)
{
scanf(“%d”,&a[i]);
}
printf(“Enter the size of array B\n”);
scanf(“%d”, &n);
printf(“Enter the sorted element of Array B\n”);
for(i=0;i<n;i++)
{
scanf(%d”,&b[i]);
}
for(i=0;i<5;i++)
{
c[i]=a[i];
c[i+5]=b[i];
}
printf(“Merge Array is \n”);
for(i=0;i<n;i++)
{
for(j=i+1;j<10;j++)
{
if(c[i]>c[j])
{
temp=c[i];
c[i]=c[j];
c[j]=temp;
}
}
}
for(i=0;i<10;i++)
{
printf(“%d”, c[i]);
}
getch();

}

Algorithm for Merging Two Arrays

  1. Create three arrays a1[100],a2[100],a3[200]
  2. Enter the elements p and q in ascending order in a1 and a2
  3. Initialize m and n(lower bound to 0)
  4. Check if(a[m]<=b[n])[Assign elements of array a1 to a3] a3[c]=a2[n+1]Set c= c+1Else[Assign elements of a2 to a3] a3[c]= a2[n++]Set c= c+1[End of If Structure]
  5. Assign remaining elements of a1 and a2 to a3
  6. Display the elements of a3
  7. End

Program in C to Traverse an Array

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a[10];
clrscr();
printf(“Enter the length of array\n”);
scanf(“%d”,&n);
printf(“Enter the element of array\n”);
for(i=0;i<=n;i++)
{
scanf(“%d”,&a[i]);
}
printf(“Traversing of the array\n”);
for(i=0;i<=n-1;i++)
printf(“\n%d”,a[i]);
getch();

Algorithm for Traversing of Array

Let LB be the lower bound and UB be the upper bound of linear array a
  1. [Initialize counter] Set I at lower bound LB
  2. Repeat for i=LB to UB
  3. [visit element] Display a[i]
  4. [End of loop]
  5. Exit

Program in C to Insert an Element at the Specified Position in Array

#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,n,k,item,pos;
clrscr();
printf(“Enter the element of array=\n”);
scanf(“%d”,&n);
printf(“Enter the element of array=\n”);
for(i=1;i<=n;i++)
{
scanf(%d”,&a[i]);
}
printf(“Enter the position”);
scanf(“%d”,&k);
for(i=n;i>=pos;i--)
{
a[i+1]=a[i];
}
printf(“Enter the value you want to insert\n”);
scanf(“%d”,&item);
for(i=1;i<=n;i++)
{
printf(“Element is %d”,a[i]);
}
getch();

}

Algorithm for Deletion in One Dimensional Array

  1. Set item= a[pos]
  2. Repeat for j=pos to n-1[Shifting elements one position upwards]Set a[j]=a[j+1][End of loop]
  3. Reset n=n-1
  4. Display the new list of element
  5. End

Algorithm for Insertion in One–Dimensional Array

  1. [Initialize the value of i] Set i=len
  2. Repeat for i=len down to pos[Shift the elements down by one position]Set a[i+1]=a[i][End of loop]
  3. [insert the elements at required position]Set a[pos]=num
  4. [Reset len] Set len= len+1
  5. Display the new list of arrays
  6. End

Program To Print a Series of Same Numbers

               11111
               2222
               333
               44
               5  */

#include <stdio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the Value\n");
for (a=1;a<=5;++a)
{
printf("\n");
for (b=5;b>=a;--b)
printf("%d",a);
}
getch();
}

Program To Print Reverse Series of different numbers

               54321
               5432
               543
               54
               5  */

#include <stdio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the Value\n");
for (a=1;a<=5;++a)
{
printf("\n");
for (b=5;b>=a;--b)
printf("%d",b);
}
getch();

}

Program to Print Series

               1
               22
               333
               4444
               55555 */

#include <stdio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the Value=\n");
for (a=1;a<=5;++a)
{
printf("\n");
for (b=1;b<=a;++b)
printf("%d",a);
}
getch();

}

Program to Print Series

               1
               12
               123
               1234
               12345 */

#include <stdio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the Value\n");
for (a=1;a<=5;++a)
{
printf("\n");
for (b=1;b<=a;++b)
printf("%d",b);
}
getch();

}

Program to a Print Factorial of a Number

#include <stdio.h>
void main()
{
int a,b,F=1;
clrscr();
printf("Enter the Value");
scanf("%d",&b);
for (a=1;a<=b;++a)
F=F*a;
printf("%d",F);
getch();

}

Tuesday, 9 July 2013

Program to Check Year is Leap or Not

#include <stdio.h>
void main()
{
int year;
clrscr ();
printf("Enter the number");
scanf("%d",&year);
if(year%4==0)
printf(%d is "Leap Year");
else
printf(%d is "Not Leap Year");
getch();

}

Program to Calculate Volume of a Sphere

#include<stdio.h>
#include<conio.h>
void main()
{
int r,volume;
clrscr ();
printf("Enter the number");
scanf("%d",&r);
volume=(4*3.14+r*r*r)/3;
printf("%d",volume);
getch();

}

Program to calculate Volume of a Cube

#include <stdio.h>
void main()
{
int l,volume;
clrscr ();
printf("Enter the number");
scanf("%d",&l);
volume=l*l*l;
printf("%d",volume);
getch();

}

Program to find Volume of a Cuboid

#include <stdio.h>
void main()
{
int l,b,h,volume;
clrscr ();
printf("Enter the number");
scanf("%d%d%d",&l,&b,&h);
volume=l*b*h;
printf("%d",volume);
getch();

}

Program to calculate Area of Angular Lateral Triangle

#include <stdio.h>
void main()
{
int l,h;
float area;
clrscr ();
printf("Enter the number");
scanf("%d%d",&l,&h);
area= 0.5*l*h;
printf("%f",area);
getch();

}

Program to find the Area of Circle

#include <stdio.h>
void main()
{
int r;
float Area;
clrscr ();
printf("Enter the number");
scanf("%d",&r);
Area= 3.14*r*r;
printf("%f",Area);
getch();

}

Monday, 8 July 2013

Program to calculate Compound of Interest

#include <stdio.h>
void main()
{
int p,r,t;
float CI;
clrscr ();
printf("Enter the number");
scanf("%d%d%d",&p,&r,&t);
CI=p*pow((1+r)/100,t);
printf("%f",CI);
getch();

}

Program to print program to calculate Simple Interest

#include <stdio.h>
void main()
{
int p,r,t;
float SI;
clrscr ();
printf("Enter the number");
scanf("%d%d%d",&p,&r,&t);
SI=(p*r*t)/100;
printf("%f",SI);
getch();

}

Program to print 3 digit number and print it is armstrong or not

#include <stdio.h>
void main()
{
int n,a,b,c,x,t;
clrscr ();
printf("Enter the 3 number");
scanf("%d",&n);
a= n%10;
x= n/10;
b= x%10;
c= x/10;
t=a*a*a+b*b*b+c*c*c;
if(t==n)
printf("It is armstrong");
else
printf("Not Armsrong");
getch();

}

Program to print Addition, Subtraction, Multiplication and Division of two numbers

#include <stdio.h>
void main()
{
int a,b,c,d,e,f;
clrscr ();
printf("Enter the two number");
scanf("%d%d",&a,&b);
c= a+b;
d= a-b;
e= a*b;
f= a/b;
printf("\n\t%d\n\t%d\n\t%d\n\t%d",c,d,e,f);
getch();

}

Program to print and calculate sum of 5 numbers

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,Sum;
clrscr();
printf("Enter the five numbers");
scanf("%d%d%d%d%d",&a,&b);
Sum=a+b+c+d+e;
printf("%d",Sum);
getch();

}

Program to display name without using printf

#include<stdio.h>
void main()
{
clrscr();
puts("Innovators With C");
getch();

}