Thursday, August 27, 2015

WRITE A C PROGRAM TO INSERT THE ELEMENT INTO THE ARRAY

INSERT ELEMENT

#include<stdio.h>
void main()
{
int n,i,a[100],position,value;
printf("Enter the array size\n");
scanf("%d",&n);
printf("Enter the %d elements in the array\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the element you have to insert\n");
scanf("%d",&position);
printf("Enter the value to insert\n");
scanf("%d",&value);
for(i=n-1;i>=position-1;i--)
a[i+1]=a[i];
a[position-1]=value;
printf("The sorted array is\n");
for(i=0;i<=n;i++)
printf("%d\n",a[i]);


}

OUTPUT:



Read More

ADDITION OF MATRICES USING C LANGUAGE

ADDITION OF MATRICES

#include<stdio.h>
void main()
{
int m,n,c,d,first[10][10],second[10][10],sum[10][10];
printf("Enter the number of rows and colmns of matrix\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of first matrix\n");
for(c=0;c<m;c++)
for(d=0;d<n;d++)
scanf("%d",&first[c][d]);
printf("Enter the elements of second matrix\n");
for(c=0;c<m;c++)
for(d=0;d<n;d++)
scanf("%d",&second[c][d]);
printf("sum of entered matrices\n");
for(c=0;c<m;c++)
{
for(d=0;d<n;d++)
{
sum[c][d]=first[c][d]+second[c][d];
printf("%d\t",sum[c][d]);
}
printf("\n");
}

}

OUTPUT:


Read More

DECIMAL TO BINARY CONVERSION IN C

DECIMAL TO BINARY

#include<stdio.h>
void main()
{
int n,c,k;
printf("Enter the value to convert the decimal to binary");
scanf("%d",&n);
printf("%d in binary system is:",n);
for(c=31;c>=0;c--)
{
k=n>>c;
if(k&1)
printf("1");
else
printf("0");
}

}

OUTPUT:


Read More

C PROGRAM TO IMPLEMENT THE MATRIX MULTIPLICATION

MATRIX MULTIPLICATION

#include<stdio.h>
void main()
{
int m,n,c,d,p,q,k,sum=0;
int first[10][10],second[10][10],multiply[100][100];
printf("Enter the number of rows and columns of first matrix\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of first matrix\n");
for(c=0;c<m;c++)
for(d=0;d<n;d++)
scanf("%d",&first[c][d]);
printf("Enter the number of rows and columns of second matrix\n");
scanf("%d%d",&p,&q);
if(n!=q)
printf("Matrices with entered orders cannot multiplied with each other\n");
else
{
printf("Enter the elements of second matrix\n");
for(c=0;c<p;c++)
for(d=0;d<q;d++)
scanf("%d",&second[c][d]);

for(c=0;c<m;c++)
{
for(d=0;d<q;d++)
{
for(k=0;k<p;k++)
{
sum=sum+first[c][k]*second[k][d];
}
multiply[c][d]=sum;
sum=0;
}
}
printf("product of enteed matrices\n");
for(c=0;c<m;c++)
{
for(d=0;d<q;d++)
printf("%d\t",multiply[c][d]);
printf("\n");
}
}


}

OUTPUT:


Read More

JAVA PROGRAM TO IMPLEMENT THE LINEAR SEARCH

LINEAR SEARCH

import java.io.*;
import java.util.*;
class linear{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n,c,search;
System.out.println("Enter the number");
n=s.nextInt();
int a[]=new int[n];
System.out.println("Enter "+n+" elements");
for(c=0;c<n;c++)
a[c]=s.nextInt();
System.out.println("Enter the search element");
search=s.nextInt();
for(c=0;c<n;c++){
if(a[c]==search){
System.out.println("the element is located at location "+(c+1));
break;
}


}
if(c==n){
System.out.println("the element is not present in the array");
}

}

}

OUTPUT:


Read More

JAVA PROGRAM FOR IMPLEMENT THE BUBBLE SORT

BUBBLE SORT

import java.io.*;
import java.util.*;
class bubble{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n,temp,c,d,i;
System.out.println("Enter the number");
n=s.nextInt();
int array[]=new int[n];
System.out.println("Enter "+n+" Elements");
for(i=0;i<n;i++)
array[i]=s.nextInt();
for(c=0;c<n-1;c++){
for(d=0;d<n-c-1;d++){
if(array[d]>array[d+1]){
temp=array[d+1];
array[d+1]=array[d];
array[d]=temp;
}
}
}
System.out.println("the sorting array are");
for(c=0;c<n;c++)
System.out.println(array[c]);
}
}

OUTPUT:


Read More

Live Traffic

Popular Posts

Designed By RAJESH GOWRABATHUNI