Search (Article Or Program)

18 June 2011

Fibonacci

#include
#include
main()
{
clrscr();
printf("\t\t\t>>>>>>>>>>>>>>FIBONACCI SERIES<<<<<<<<<<<<<<\n\n");
int s,t,m=0,n=1,c=1;
printf("Enter a No.");
scanf("%d",&t);
while(c!=t)
{
printf("%d\n",n);
s=m+n;
c=c+1;
m=n;
n=s;
}
printf("%d",n);
getch();
}

Factorial (in C)

#include
#include
facto(double a,double b)
{
double c;
for(a=1; a<=c;a=a+1)
{
b=b*a;
}
return(b);
}
main()
{
clrscr();
double i,f=1,m;
printf("Enter a number ");
scanf("%lf",&m);
for(i=1; i<=m;i=i+1)
{
f=f*i;
}
printf("%lf", f);
getch();
}

Tell weather a number is odd or even (in C)

/*Tell weather a number is odd or even:*/
#include
#include
main()
{
clrscr();
int n;
printf("Please enter an integer: ");
scanf("%d",&n);
if(n%2!=0)
printf("%d is odd\n",n);
else
printf("%d is even\n",n);
getch();
}

Diagonal Print (IN C)

#include
#include
main()
{
clrscr();
int i,j,k,space=1;
for(j=10;j>=1;j--)
{for(i=1;i<=j;i++) { printf("*"); } for(int m=0;m=1;k--)

{
printf("*");
}

printf("\n");
space=space+2;
}
getch();
}

Character Count (in C)

//character count
#include
#include
main()
{
int count=0;
clrscr();
printf("\n\t\t >>>>>>>>>>>>>>>>>>>Character Count <<<<<<<<<<<<<<<<<<\n\n");
printf("\n\nType in a phrase : ");
while(getche()!='\r')
count++;
printf("\n\nCharacter count is %d : ",count);
getch();

}

Colour Print in C

#include
#include

int main(void)
{
int i, j;

clrscr();
for (i=0; i<9 br="" i=""> {
for (j=0; j<80 br="" j=""> cprintf("FKj");
cprintf("\r\n");
textcolor(i+1);
textbackground(i);
}

getch();
}

Bye Bye Print

//wrtiten by by by by by\\
#include
#include
main()
{
clrscr();
int i;
textcolor(165);
gotoxy(15,20);
cprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
gotoxy(15,21);
cprintf("$$$ $$$ $$$$ $$$ $$$ $$$$ $$$\n");
gotoxy(15,22);
cprintf("$$$ $$$$ $$$ $$$$ $$$ $$$$ $$$ $$$$ $$$\n");
gotoxy(15,23);
cprintf("$$$ $$$$ $$$ $$$$ $$$ $$$$ $$$ $$$$ $$$\n");
gotoxy(15,24);
cprintf("$$$ $$$ $$$ $$$ $$$\n");
gotoxy(15,25);
cprintf("$$$ $$$$ $$$$$$ $$$$$$ $$$$ $$$$$$ $$$$$$\n");
gotoxy(15,26);
cprintf("$$$ $$$$ $$$$$$ $$$$$$ $$$$ $$$$$$ $$$$$$\n");
gotoxy(15,27);
cprintf("$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$\n");
gotoxy(15,28);
cprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
getch();
}

Bubble Sort (in C++)

#include
#include
void main()
{
clrscr();
int a[100],i,n,j,temp;
cout<<"How many element: "; cin>>n;
cout<<"Enter the elements of array: "<>a[i];
cout<<"The elements of array Before Sorting: "<a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"Elements of array After Sorting: "< for(i=0;i cout< getch();
}

Bubble Sort (in C++)

//bubble sort program//
#include
#include
main()
{
clrscr();
int n=4;
int data[5];
int t;
int ptr;
cout<<"\nInsert Numbers five Numbers for sorting\n"; for(int i=0;i<=n;i++) { cin>>data[i];
}
for(int k=1;k<=n-1;k++) { ptr=0; while(ptr<=n-k) { if (data[ptr]>data[ptr+1])
{
t=data[ptr];
data[ptr]=data[ptr+1];
data[ptr+1]=t;
}
ptr++;
}
for(int i=0;i<=n;i++)
{
cout< cout<<"\n";
}
getch();

} }

Binary Search

#include
#include
void main()
{
clrscr();
int a[100],i,loc,mid,beg,end,n,flag=0,item;
cout<<"How many element: "; cin>>n;
cout<<"Enter (IN ORDER) the elements of array: "<>a[i];
cout<<"Enter the element to be searched: "; cin>>item;
loc=0;
beg=0;
end=n-1;
while((beg<=end)&&(item!=a[mid]))
{
mid=(beg+end)/2;
if(item==a[mid])
{
cout<<"Search successful :)";
loc=mid;
cout<<"Position of the Item: "< flag=flag+1;
}
else if(item end=mid-1;
else
beg=mid+1;
}
if(flag==0)
{
cout<<"Search NOT sucessfull :( ";
}
getch();
}

Using array the average height of students

//*Height of Student*//
#include
#include
main()
{
float hgt[30];
int n,stdn;
float sum=0;
clrscr();
gotoxy(15,5);
printf("Using array the average height of students \n\n\n");
printf("Enter how many : ");
scanf("%d",&n);
for(stdn=1;stdn<=n;stdn++)
{
printf("\nEnter height of student %d :",stdn);
scanf("%f",&hgt[stdn]);
}
for(stdn=1;stdn<=n;stdn++)
{
sum+=hgt[stdn];
}
printf("\n\n\n\nThe average is %f",sum/n);
getche();
}

Array Menu Program (without pointers) insertion,deletion,print,traverse

/*array insertion,deletion,print,traverse*/
#include
#include
#include
int arr[5];
// insertion function
void a_insert(int num, int pos)
{
for(int i=4; i>=pos;i--)
arr[i]=arr[i-1];
arr[i]=num;
}
// deletion function
void a_delete(int pos)
{
for(int i=pos; i<=4;i++) arr[i-1]=arr[i]; arr[i-1]=0; } void main(void) { int ch,num,pos; while(1) { clrscr(); cout<<"\nMenue Program of Array\n"; cout<<"\n1. Insertion in Array"; cout<<"\n2. Deleteion in Array"; cout<<"\n3. Print the Array"; cout<<"\n4. Traevers the Array"; cout<<"\n5. Quit\n"; cin>>ch;

switch(ch)
{
case 1:
cout<<"enter element:"; cin>>num;
cout<<"enter position:"; cin>>pos;
a_insert(num,pos);
break;
case 2:
cout<<"enter pos.:"; cin>>pos;
a_delete(pos);
break;
case 3:
cout<<"\nArray:";
for(int i=0;i<5 br="" i=""> cout< getch();
break;
case 4:
for(i=0;i<5 br="" i=""> {
cout< cout< }
getch();
break;
case 5:
exit(0);
break;
default:
cout<<"Invalid Selection";
}
}
}

Array Insertion

#include
#include
main()
{
int n,t[5],i;
for(i=1;i<5 br="" i=""> {
scanf("%d",&t[i]);
}

getch();
}

Age in Minutes Program

#include
#include
main()

{
clrscr();
float years,minuts;
printf("\t\t********** calculate age in minutes **********\n\n\n\n\n ");
printf("\tPlease type your age in years : ");
scanf("%f",&years);
minuts=years*365*24*60;
printf("\n\n\tYou are %.1f minutes old.",minuts);
getch();
}

L.C.M of Three Numbers (in C)

#include
#include
main()
{
clrscr();
printf("\t\t>>>>>>>>>>>>L.C.M of 3 Numbers<<<<<<<<<<\n\n");
int a,b,c,l,m,n,r,x,y,z;
printf("Enter 1st Number : \n");
scanf("%d",&a);
printf("Enter 2nd Number :\n");
scanf("%d",&b);
printf("Enter 3rd Number :\n");
scanf("%d",&c);
x=a;
y=b;
z=c;
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
l=(x*y)/a;
m=l;
while(c!=0)
{
r=l%c;
l=c;
c=r;
}
n=(m*z)/l;
printf("The result is %d",n);
getch();
}

L.C.M of Two Numbers (in C)

#include
#include
main()
{
clrscr();
printf("\t\t>>>>>>>>>>>>L.C.M of 2 Numbers<<<<<<<<<<\n\n");
int a,b,r,c,d,l;
printf("Enter no 1\n");
scanf("%d",&a);
printf("Enter no 2\n");
scanf("%d",&b);
c=a;
d=b;
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
l=(c*d)/a;
printf("The result is %d",l);
getch();
}

G.C.D program of Three Number (in C)

#include
#include
main()
{
int a,b,c,r;
scanf("%d %d %d",&a,&b,&c);
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
while(c!=0)
{
r=a%c;
a=c;
c=r;
}
printf("%d\n",a);
getch();
}

G.C.D program of Two Number (in C)

#include
#include
main()
{
int a,b,r;
scanf("%d %d",&a,&b);
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
printf("%d\n",a);
getch();
}

For Loop Print program (in c)

#include //header files stdio.h and conio.h//
#include
main()
{
int i,n;
scanf("%d",&n);
for(i=1;i<=n;i=i+1)
{
printf("%d\n",i);
}
getch();
}

09 June 2011

menue program of array with (using) Pointers 1. insert 2. delete 3. searchin 4. replace

/*menue program of array 1. insert 2. delete 3. searchin 4. replace*/
#include
#include
#include
#include
void display(int);
void insert(int*);
void traverse(int*);
void deletion(int*,int);
void sort(int*);
void search(int*,int);
static int n;
int main()
{
clrscr();
int choice=10,pos,ele;
int*x;
printf("\n\n\n\n\n\nEnter Number of elements in array;");
scanf("%d",&n);
x=(int*)malloc(n*sizeof(int));
while(choice!=0)
{
printf("\n\n\n\n\n\n\n\n\nOperation MENUE\n\n\n\n\n\n\n");

printf("1.Insert an integer\n");
printf("2.Traverse the ADT-Array\n");
printf("3.Delete an Element\n");
printf("4.Sort the Array\n");
printf("5.Search an Interger\n");
printf("6.Exit the Program\n");
printf("Insert Your Choice Number\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
insert(x);
getch();
break;
case 2:
traverse(x);
getch();
break;
case 3:
printf("\n\n\n\n\n\n\n Please enter the postion of element to be deleted;\n");
scanf("%d",&pos);
deletion(x,pos);
traverse(x);
getch();
break;
case 4:
sort(x);
traverse(x);
getch();
break;
case 5:
printf("\n\n\n\nPlease Enter The Element to be Searched\n:");
scanf("%d",&ele);
search(x,ele);
getch();
break;
case 6:
exit(0);
getch();
break;
}
}
return 0;
}
/*insert in array*/
void insert(int*p)
{
int i=0,val;
while(i!=n)
{
printf("\n\n\n\n\nInser the value to be Inserted\n");
scanf("%d",&val);
p[i]=val;
i++;
}
}
/*****traversal*********/
void traverse(int*p)
{
int i=0;
while(i!=n)
{
printf("\n\n\n\n\n\n %d\n",p[i]);
i++;
}
}
/*deletion*/
void deletion(int*p,int a)
{
int i=a;
printf("\n\n\n\n\nthe number deleted is : %d",p[i-1]);
i=a-1;
while(ip[j])
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
}
/*search*/
void search(int*p,int a)
{
int i=0;
int flag=0;
while(i<=n)
{
if(p[i]==a)
{
flag=1;
printf("\the element found at position %d",i+1);
break;
}
i++;
}
if(flag==0)
printf("\n\n\n\n\n\n\nsearch ended unsuccessfully. elelment NOt found!!!;-(");
}