Friday, July 31, 2009

yahoo-microsoft deal

given matrix is symmetric or not using c.

//program to find symmetry of a given matrix
#include
#include
void main()
{
int a[10][10],count=0,i,j,m,n;
clrscr();
printf("\nEnter the rows and columns of matrix :");
scanf("%d %d",&m,&n);

if(m!=n)
{
count++;
printf("the given matrix is not symmetric matrix since rows and columns are not equal\n");
}

else
{
printf("\n enter the matrix a:");
for(i=0;i for(j=0;j scanf("%d",&a[i][j]);

for(i=0;i for(j=0;j {
if(a[i][j]!=a[j][i])
{
count++;
break;
}
}
if(count==0)
printf("\nThe given matrix is symmetric matrix");
else
printf("\nThe given matrix is not symmetric matrix");

}
getch();

}




find adams number using c

//wap to find wether the given number is adams number or not
#include
#include
#include
void main()
{
int n,temp;
char ch;
clrscr();
do
{
printf("\nEnter the number:");
flushall();
scanf("%d",&n);
temp=n*n;
temp=rev(temp);
temp=sqrt(temp);
temp=rev(temp);

if(temp==n)
printf("the given number %d is adams number",n);
else
printf("The given number %d is not adams number",n);

printf("\nDo you want to continue(Y/N)");
flushall();
scanf("%c",&ch);
if(ch=='Y'||ch=='y')
continue;
else
break;
}while(1);
getch();
}
int rev(int x)
{
int n,tot=0;
n=x;
while(n!=0)
{

x=n%10;
tot=tot*10+x;
n=n/10;
}
return(tot);
}

Thursday, July 30, 2009

multiplication of two matrices

//program for multiplication of two rectaangular matrices
#include
#include
void main()
{
int a[10][10],b[10][10],c[10][10],r,i,j,k,m,n;
clrscr();

printf("\nEnter the rows and columns of matrix :");
scanf("%d %d",&m,&n);
printf("\n enter the matrix a:");
for(i=0;i for(j=0;j scanf("%d",&a[i][j]);
printf("\nEnter the no of columns of matrix :");
scanf("%d",&r);
printf("\n enter the matrix b:");
for(i=0;i for(j=0;j scanf("%d",&b[i][j]);

printf("the multiplication of mtrices a and b is c:\n");
for(i=0;i {
for(j=0;j {
c[i][j]=0;
for(k=0;k c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
printf("%d ",c[i][j]);
}
printf("\n");
}
getch();
}

sorting string in alphabetical order

#include
#include
#include
void main()
{
char str[10],temp;
int i,n,j,c;
clrscr();

printf("Enter the string to be converted in alphabetical order:");
scanf("%s",str);
n=strlen(str);

for(i=0;str[i]!='\0';i++)
for(j=i+1;j {
if(str[i]>str[j])
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
}
}
getch();

}

sorting strings by alphabetical order using c

#include
#include
#include
void main()
{
char str[10][10],temp[10];
int i,n,j,c;
clrscr();

printf("\nEnter the number of strings to be entered:");
scanf("%d",&n);
printf("Enter the strings:");
for(i=0;i scanf("%s",str[i]);

for(i=0;str[i]!='\0';i++)
for(j=i+1;j {
c=strcmp(str[i],str[j]);
if(c>0)
{
strcpy(temp,str[j]);
strcpy(str[j],str[i]);
strcpy(str[i],temp);
}
}

printf("\nThe strings after sorting are:\n");
for(i=0;i printf("%s\n",str[i]);

getch();
}

binary search using clanguage

//program to findwhether the numbber is in given list using binary search
#include
#include
void main()
{
int a[10],i,n,mid,high,low,count=0,n1;
clrscr();

printf("\nEnter the num of elements in the array:");
scanf("%d",&n);
printf("\nEnter the elements into the array");
flushall();
for(i=0;i scanf("%d",&a[i]);
printf("\nEnter the number to be searched in the list:");
scanf("%d",&n1);
low=a[0];
high=a[n-1];
mid=(low+high)/2;
while(1)
{
if(mid==n1)
{
count++;
break;
}
else if(mid>n1)
{
high=mid-1;
}
else if(mid {
low=mid+1;
}
if(low>=high)
break;
// else if((mid==high)||(mid==low))
// break;
mid=(high+low)/2;

}
if(count==0)
printf("\nThe number %d is in not in given list",n1);
else
printf("\nThe number %d is in given list",n1);

getch();
}

linear search using c language

//program to findwhether the numbber is in given list
#include
#include
void main()
{
int a[10],n,i,j,count=0,n1;
clrscr();

printf("\nEnter the num of elements in the array:");
scanf("%d",&n);
printf("\nEnter the elements into the array");
flushall();
for(i=0;i scanf("%d",&a[i]);
printf("\nEnter the number to be searched in the list:");
scanf("%d",&n1);
for(i=0;i {
if(a[i]==n1)
{ count++;
break;
}
}
if(count!=0)
printf("\nthe number %d is in given list",n1);
else
printf("\nthe number %d is not in given list",n1);
getch();
}

linear sort using c language

//program to sort the elements using linear sort
#include
#include
void main()
{
int a[10],n,i,j,temp;
clrscr();

printf("\nEnter the num of elements in the array:");
scanf("%d",&n);
printf("\nEnter the elements into the array");
flushall();
for(i=0;i scanf("%d",&a[i]);

for(i=0;i {
for(j=i+1;j if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
printf("the numbers after sorting are:");
for(i=0;i printf("%d ",a[i]);
getch();

}

bubble sort using c language

//program to sort the elements using bubble sort
#include
#include
void main()
{
int a[10],n,i,j,temp;
clrscr();

printf("\nEnter the num of elements in the array:");
scanf("%d",&n);
printf("\nEnter the elements into the array");
flushall();
for(i=0;i scanf("%d",&a[i]);

for(i=0;i {
for(j=0;j if(a[j]>a[j+1])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
printf("the numbers after sorting are:");
for(i=0;i printf("%d ",a[i]);
getch();

}

remove duplicates from given list of numbers

#include
#include
void main()
{
int a[10],n,i,j; clrscr();
printf("\nEnter the num of elements in the array:");
scanf("%d",&n);
printf("\nEnter the elements into the array");
flushall();
for(i=0;i {
scanf("%d",a[i]);
for(j=0;j{ if(a[i]==a[j])
{ i--;
n--;
}
}
}
printf("\nThe elements in array without duplicates are:");

for(i=0;iprintf("%d ",a[i]);
getch();
}