Binary To Decimal and Decimal To Binary Conversion
Binary To Decimal and Decimal To Binary Conversion
CONVERSION
# include <iostream.h>
#include<math.h>
void main()
{
int ans[100],input[10],x,choice;
while (choice!=-1)
{
cout<<"\n Which of the operations do you want to perform."<<endl;
cout<<"(1) Binary to Decimal Conversion "<<endl;
cout<<"(2) Decimal to Binary Conversion "<<endl;
cout<<"Select the operation or press -1 to exit: ";
cin>>choice;
switch (choice)
{
case 1:
{
break;
}
case 2:
{
for(i=0;i<cnt;i++)
cout<<rev_ans[cnt1];
break;
}
}
SEARCHING A NAME IN A 2D ARRAY
# include <iostream.h>
#include<math.h>
#include<string.h>
void main()
{
char name[5][20];
char name1[20];
cout<<"Enter 5 names: "<<endl;
for(int i=0;i<5;i++)
cin>>name[i];
cout<<"Enter the name to be searched: "<<endl;
cin>>name1;
int chk=0;
int ind;
for(i=0;i<5;i++)
{
if(strcmp(name1,name[i])==0)
{
chk=1;
ind=i;
break;
}
}
if(chk==1)
cout<<"The name exists at index: "<<ind<<endl;
else
cout<<"The name doesnt exist"<<endl;
}
BUBBLE SORT
# include <iostream.h>
#include<math.h>
#include<string.h>
void main()
{
int size;
cout<<"Enter the size of the array: "<<endl;
cin>>size;
const int size1=100;
int array[size1];
cout<<"Enter the array elements: "<<endl;
for(int i=0;i<size;i++)
cin>>array[i];
for(i=0;i<size-1;i++)
{
for(int j=i+1;j<size;j++)
{
if(array[i]>array[j])
{
int temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
cout<<"Array in ascending order: "<<endl;
for(i=0;i<size;i++)
cout<<array[i];
cout<<endl;
}