Thursday, 7 July 2016

Write a program in C language that accepts two matrices as input and prints their products


#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],m,n,i,j,l,k;
clrscr();
printf("\nEnter order of A matrix: ");
scanf("%d %d",&m,&n);
printf("Enter A matrix \n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\nEnter order of B matrix: ");
scanf("%d %d",&n,&l);
printf("Enter B matrix \n");
for(i=0;i<n;i++)
for(j=0;j<l;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<l;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
printf("\n Resultantant matrix is \n");
for(i=0;i<m;i++)
{
for(j=0;j<l;j++)
printf("%6d",c[i][j]);
printf("\n");
}
getch();
}

OUTPUT:




DOWNLOAD

Write a program in C language to implement Linear search


#include<stdio.h>
#include<conio.h>
void main()
{
int arr[20],n,i,m,f=0;
clrscr();
printf("How many numbers: ");
scanf("%d",&n);
printf("\n");
for(i=0;i<n;i++)
{
printf("Enter element %d: ",i+1);
scanf("%d",&arr[i]);
}
printf("\nEnter the element you want to search: ");
scanf("%d",&m);
for(i=0;i<n;i++)
{
if(arr[i]==m)
{
printf("\n\tItem found at location %d",i+1);
f=1;
break;
}
}
if(f==0)
printf("\nItem not found!!!");
getch();
}


OUTPUT:







Wednesday, 6 July 2016

Write a shell script in Linux/Unix that accepts a text file as input and prints the number of words in the file which have at least one vowel as output

#!/bin/bash
file=$1
v=0
if [ $# -ne 1 ]
then
echo "$0 fileName"
exit 1
fi
if [ ! -f $file ]
then
echo "$file not a file"
exit 2
fi
while read -n 1 c
do
l=$(echo $c | tr [:upper:] [:lower:])
[[ "$l" == "a" || "$l" == "e" || "$l" == "i" || "$l" == "o" || "$l" == "u" ]] && (( v++ ))
done < $file
echo "Vowels : $v"
echo "Characters : $(cat $file | wc -c)"
echo "Blank lines : $(grep -c '^$' $file)"
echo "Lines : $(cat $file|wc -l )"

OUTPUT:


Print Friendly and PDF

Write a program in C language that will accept a Graph as input and will generate its Minimum Cost Spanning Tree


#include<stdio.h>
#include<conio.h>
int a,b,u,v,n,i,j,ne=1;
int visited[10]={0},min,mincost=0,cost[10][10];
void main()
{
clrscr();
printf("\n Enter the number of nodes:");
scanf("%d",&n);
printf("\n Enter the adjacency matrix:\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
scanf("%d",&cost[i][j]);
if(cost[i][j]==0)
cost[i][j]=999;
}
visited[1]=1;
printf("\n");
while(ne<n)
{
for(i=1,min=999;i<=n;i++)
for(j=1;j<=n;j++)
if(cost[i][j]<min)
if(visited[i]!=0)
{
min=cost[i][j];
a=u=i;
b=v=j;
}
if(visited[u]==0 || visited[v]==0)
{
printf("\n Edge %d:(%d %d) cost:%d",ne++,a,b,min);
mincost+=min;
visited[b]=1;
}
cost[a][b]=cost[b][a]=999;
}
printf("\n Minimun cost=%d",mincost);
getch();
}

OUTPUT:



Monday, 4 July 2016

Write a Java program to create an Applet to generate table of 10

import java.applet.Applet;
import java.awt.*;
public class tableof10 extends Applet {
      int count,i;
 
   public void init(){
      this.count=10;
    }

    public void paint(Graphics g) {
        for(i=1;i<=10;i++)
        {
            g.drawString(i+ "* 10 =" +i*10,150,count);
            count=count+20;
        }
   
    }

}

Applet code:

<html>
     <head>
          <title>table of 10</title>
     </head>
     <body>
          <applet code="tableof10.class" height="500" width="500"></applet>
     </body>
</html>

OUTPUT:

Sunday, 3 July 2016

Write a program using JAVA to create an Applet that takes radius of a circle as input and draws the circle in Blue color

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class NewApplet extends Applet implements ActionListener{

    TextField t1;
    Button b1;
    Label l1;
    int r=0;

    public void init() {
        l1 = new Label("Enter radius of circle:");
        t1 = new TextField(5);
        b1 = new Button("Draw Circle");
        add(l1);
        add(t1);
        add(b1);
    b1.addActionListener(this);
    }

   public void paint(Graphics g)
{
    g.drawOval(50, 50, r*2, r*2);
    g.setColor(Color.blue);
    g.fillOval(50, 50, r*2, r*2);
}

public void actionPerformed(ActionEvent e)
{
r= Integer.parseInt(t1.getText());
repaint();
}
}

Applet code:

<html>
     <head>
          <title>circle in Blue color</title>
     </head>
     <body>
          <applet code="NewApplet.class" width="800" height="800"></applet>
     </body>
</html>

OUTPUT:

Print Friendly and PDF

Write a Java program to create two threads T1 and T2. Thread T1 is having priority six and thread T2 is having default priority assigned to it. Implement threads T1 and T2 in such a way that T1 prints table of 2 and T2 prints table of 5

class T1 extends Thread{

public void run(){
        int i;
        for(i=1;i<=10;i++)
        System.out.println(i+"*"+"2"+"="+i*2);
}
}

class T2 extends Thread{

public void run(){
        int i;
        for(i=1;i<=10;i++)
        System.out.println(i+"*"+"5"+"="+i*5);
}
}


public class T3 {
 
    public static void main(String[] args){
 
    T1 t1=new T1();
    T2 t2=new T2();
    t1.setPriority(6);
    t1.start();
    t2.start();
    }
 
}

OUTPUT:

1*2=2
2*2=4
3*2=6
4*2=8
5*2=10
6*2=12
7*2=14
8*2=16
9*2=18
10*2=20
1*5=5
2*5=10
3*5=15
4*5=20
5*5=25
6*5=30
7*5=35
8*5=40
9*5=45
10*5=50

Popular Posts