Saturday, February 28, 2015

Merge Sorting Program In C++

#include<iostream.h>
#include<conio.h>
void display(int *A,int s){
cout<<"\n";
for(int i=0;i<=s;i++){
cout<<A[i]<<"  ";
}}
void merge(int *A,int p,int q,int r)
{
int n1=q-p+1;
int n2=r-q;
int *L=new int[n1];
int *R=new int[n2];
{
for(int i=0;i<=n1;i++){
R[i]=A[p+i-1];
}

for(int j=0;j<=n2;j++){
R[j]=A[q+j];
}  }
int i=1,j=1;
for(int k=p;k<=r;k++){
if(L[i]<=R[j])
{
A[k]=L[i];
i++;
}
else{
A[k]=R[j];
j++;
}
}
}
void merge_sort(int *A,int p,int r)
{
if(p<r){
int q=((p+r)/2);
merge_sort(A,p,q);
merge_sort(A,q+1,r);
merge(A,p,q,r);
}
}
void main()
{
clrscr();
int A[]={5,4,8,7,9,1,6,3};
merge_sort(A,0,7);
display(A,7);
getch();
}

Sunday, February 8, 2015

C Program to find the determinant of a Matrix

C Program to find the determinant of a Matrix  Size id Define By User

#include<conio.h>
#include<stdio.h>

int a[20][20],m;
int determinant(int f[20][20],int a);
int main()
{
  clrscr();
  int i,j;
  printf("----------------------------------------------------------------------\n");
  printf("-----------------CODE BY PROGRAMMING SEEKERZZ ------------------------\n");
  printf("----------------------------------------------------------------------\n");
  printf("\n\nEnter order of matrix : ");
  scanf("%d",&m);
  printf("\nEnter the elements of matrix\n");
  for(i=1;i<=m;i++)
  {
  for(j=1;j<=m;j++)
  {
  printf("a[%d][%d] = ",i,j);
  scanf("%d",&a[i][j]);
  }
  }
  printf("\n\n---------- Matrix A is --------------\n");
  for(i=1;i<=m;i++)
     {
 printf("\n");
 for(j=1;j<=m;j++)
 {
      printf("\t%d \t",a[i][j]);
 }
     }
  printf("\n \n");
  printf("\n Determinant of Matrix A is %d .",determinant(a,m));
  getch();
}

int determinant(int f[20][20],int x)
{
  int pr,c[20],d=0,b[20][20],j,p,q,t;
  if(x==2)
  {
    d=0;
    d=(f[1][1]*f[2][2])-(f[1][2]*f[2][1]);
    return(d);
   }
  else
  {
    for(j=1;j<=x;j++)
    {
      int r=1,s=1;
      for(p=1;p<=x;p++)
{
 for(q=1;q<=x;q++)
   {
     if(p!=1&&q!=j)
     {
b[r][s]=f[p][q];
s++;
if(s>x-1)
{
  r++;
  s=1;
 }
      }
    }
}
     for(t=1,pr=1;t<=(1+j);t++)
     pr=(-1)*pr;
     c[j]=pr*determinant(b,x-1);
     }
     for(j=1,d=0;j<=x;j++)
     {
       d=d+(f[1][j]*c[j]);
      }
     return(d);
   }

}


Saturday, February 7, 2015

Calculator using Java script and HTML /CSS 3

Calculator
Welcome Calculator by JavaScript






By. Usman Siddique


<html>
<head>
<title> Calculator </title>
<style>
form{background-color:green;
text-align:center;
width:300px;
height:409px;margin:0 auto;
border:2px solid yellow;
}
form input{background-color:red;
width:60px;
height:60px;
margin:5px 5px;
font-size:14pt;
border-radius:50px;}
</style>

</head>
<body>

<form name="f">
<i>Welcome Calculator by JavaScript</i>
<br/>

<input type="text" name="result"  id="result" style="width:280px;
height:40px;text-indent:10px;"  >
<br/>
<input type="text" name="display"  id="display"style="width:140px;
height:25px;background-color:darkgray;font-size:10pt;text-indent:10px;" >

<input type="button" onClick="Sign()" name="sign" value="+/-" style="margin:0px 1px;width:60px;
height:25px;font-size:10pt" >

<input type="button" onClick="Clear()" value="C"  style="margin:1px 1px;width:60px;
height:25px;font-size:10pt"/>
<br/>

<input type="button" onClick="num1Perform()" name="num1" value="1" >
<input type="button" onClick="num2Perform()" name="num2" value="2" >
<input type="button" onClick="num3Perform()" name="num3" value="3" >
<input type="button" onClick="Addition()" value="+" >
<br/>
<input type="button" onClick="num4Perform()" name="num4" value="4" >
<input type="button" onClick="num5Perform()" name="num5" value="5" >
<input type="button" onClick="num6Perform()" name="num6" value="6" >
<input type="button" onClick="SubStract()" value="-" />
<br/>
<input type="button" onClick="num7Perform()" name="num7" value="7" >
<input type="button" onClick="num8Perform()" name="num8" value="8" >
<input type="button" onClick="num9Perform()" name="num9" value="9" >
<input type="button" onClick="Muliply()" value="*" />
<br/>
<input type="button" onClick="num0Perform()" name="num0" value="0" >
<input type="button" onClick="Decimal()" name="decimal" value="." />
<input type="button" onClick="Equal()" value="=" />
<input type="button" onClick="Divison()" value="/" />
<br/>
By. Usman Siddique

</form>

<script type="text/JavaScript">
var firstNum;
    var secondNum;
    var total;
    var plusminus;
    var plusClick;
    var minusClick;
    var multiplyClick;
    var devideClick;
var decimalClick;
 

function Clear() {                                
        // Clear
        document.f.result.value="";
document.f.display.value="";

    }
function num0Perform() {                                
        // Zero
document.f.display.value +=" 0";
        document.f.result.value += document.f.num0.value;
    }
function num1Perform() {                                
        // NO1
document.f.display.value +=" 1";
        document.f.result.value += document.f.num1.value;
    }
function num2Perform() {                                
        // NO2
document.f.display.value +=" 2";
        document.f.result.value += document.f.num2.value;
    }
function num3Perform() {                                
        // NO3
document.f.display.value +=" 3";
        document.f.result.value += document.f.num3.value;
    }
function num4Perform() {                                
        // NO4
document.f.display.value +=" 4";
        document.f.result.value += document.f.num4.value;
    }
function num5Perform() {                                
        // NO5
document.f.display.value +=" 5";
        document.f.result.value += document.f.num5.value;
    }
function num6Perform() {                                
        // NO6
        document.f.display.value +=" 6";
document.f.result.value += document.f.num6.value;
    }
function num7Perform() {                                
        // NO7
document.f.display.value +=" 7";
        document.f.result.value += document.f.num7.value;
    }
function num8Perform() {                                
        // NO8
document.f.display.value +=" 8";
        document.f.result.value += document.f.num8.value;
    }
function num9Perform() {                                
        // NO9
document.f.display.value +=" 9";
        document.f.result.value += document.f.num9.value;
    }
function Sign(){
document.f.display.value="-"+(document.f.result.value);
document.f.result.value="-"+(document.f.result.value);
}
function Addition(){
firstNum = (parseFloat(document.f.result.value));
document.f.display.value=(document.f.result.value)+" +";
document.f.result.value="";
plusClick = 1;
decimalClick=0

}
function SubStract(){
firstNum = (parseFloat(document.f.result.value));
document.f.display.value=(document.f.result.value)+" -";
document.f.result.value="";
minusClick=1;
decimalClick=0
}
function Muliply(){
firstNum = (parseFloat(document.f.result.value));
document.f.display.value=(document.f.result.value)+" *";
document.f.result.value="";
multiplyClick=1;
decimalClick=0
}
function Divison(){
firstNum = (parseFloat(document.f.result.value));
document.f.display.value=(document.f.result.value)+" /";
document.f.result.value="";
devideClick=1;
decimalClick=0
}
function Decimal(){
document.f.display.value=(document.f.result.value)+".";
document.f.result.value=(document.f.result.value+".");
}

function Equal(){
secondNum = (parseFloat(document.f.result.value));
if (plusClick > 0) {
total = firstNum + secondNum;
document.f.result.value=total;
document.f.display.value=firstNum +" + "+secondNum+" = "+total;
firstNum = 0;
secondNum = 0;
plusClick = 0;
}


if(minusClick>0){
total = firstNum - secondNum;
document.f.result.value=total;
document.f.display.value=firstNum +" - "+ secondNum+" = "+total;
firstNum = 0;
secondNum = 0;
minusClick = 0;

}                                    
 if(multiplyClick>0){
total = firstNum * secondNum;
document.f.result.value=total;
document.f.display.value=firstNum +" * "+ secondNum+" = "+total;
firstNum = 0;
secondNum = 0;
multiplyClick = 0;

}

if(devideClick>0){
total = firstNum / secondNum;
document.f.result.value=total;
document.f.display.value=firstNum +" / "+ secondNum+" = "+total;
firstNum = 0;
secondNum = 0;
devideClick = 0;
}
}
</script>

</body>
</html>


How to draw a circle using HTML and CSS

<html>
<style  type="text/css">
#circle{
width:100px;
height:100px;
mardin:100px auto;
background-color:red;
border-radius:100px;
}
</style>

<body>
<div id="circle"></div>
</body>
</html>

Tuesday, February 3, 2015

Monday, February 2, 2015

Augmented Matrix Solution By reducing it to Row Echelon Form in Java

Read Also:  


Augmented Matrix Solution By reducing it to Row Echelon Form And then Calculate the result by backward substitution (Code in Java) 



package echolon;
import java.util.Scanner;
/**
 *
 * @author usman
 */
public class Echolon {
     Scanner usman=new Scanner(System.in);
    int i,j,k,n,a;
    float [][] A=new float[20][20];
    float  sum;
    float c;
    float [] x=new float[10];
    
    public  Echolon(){
    sum=0;
    System.out.println("\nEnter the order of matrix: ");
    n=usman.nextInt();
    a=n;
    System.out.println("\nEnter the elements of augmented matrix row-wise:\n\n");
    for(i=1; i<=n; i++)
    {
for(j=1; j<=(n+1); j++)

            if(a<j){System.out.println("\nEnter the Value of B: (1st row):- \n ");}
   System.out.println("A["+i+"]["+j+"] : ");
            
   A[i][j]=usman.nextFloat();
}
    }
    }

    void operation() {
    for(j=1; j<=n; j++)
    {
for(i=1; i<=n; i++)
{
   if(i>j)
   {
c=A[i][j]/A[j][j];
for(k=1; k<=n+1; k++)
{
   A[i][k]=A[i][k]-c*A[j][k];
}
   }
}
    }

    x[n]=A[n][n+1]/A[n][n];
     for(i=n-1; i>=1; i--)
    {
sum=0;
for(j=i+1; j<=n; j++)
{
   sum=sum+A[i][j]*x[j];
}
x[i]=(A[i][n+1]-sum)/A[i][i];
    }
    }

    void result(){
    System.out.println("\nThe solution is: \n");
    for(i=1; i<=n; i++)
    {
System.out.println("\nx"+i+" =  "+x[i]+"\t");
    }
    }

void display()
{
System.out.println("\n The Matrix is :-\n ");
for(int i=1;i<=n;i++){
System.out.println("\n");
for(int j=1;j<=n+1;j++){
System.out.println(A[i][j]+"     ");
}}
}


public static void main(String args[]){
Echolon obj=new Echolon();
obj.operation();
obj.display();
obj.result();
}
}



Augmented Matrix Solution By reducing it to Row Echelon Form in C++

Read Also:  


Augmented Matrix Solution By reducing it to Row Echelon Form And then Calculate the result by backward substitution  (Code In C++)....


#include<iostream.h>
#include<conio.h>
class row{
    int i,j,k,n,a;
    float A[20][20],c,x[10],sum;
    public:
    row(){

    sum=0.0;
    cout<<"\nEnter the order of matrix: ";
    cin>>n;
    a=n;
    cout<<"\nEnter the elements of augmented matrix row-wise:\n\n";
    for(i=1; i<=n; i++)
    {
for(j=1; j<=(n+1); j++)
{
  if(a<j){cout<<"\nEnter the Value of B: (1st row):- \n ";}
   cout<<"A["<<i<<"]["<<j<<"] : ";
   cin>>A[i][j];
}
    }
    }

    void operation() {
    for(j=1; j<=n; j++)
    {
for(i=1; i<=n; i++)
{
   if(i>j)
   {
c=A[i][j]/A[j][j];
for(k=1; k<=n+1; k++)
{
   A[i][k]=A[i][k]-c*A[j][k];
}
   }
}
    }

    x[n]=A[n][n+1]/A[n][n];
     for(i=n-1; i>=1; i--)
    {
sum=0;
for(j=i+1; j<=n; j++)
{
   sum=sum+A[i][j]*x[j];
}
x[i]=(A[i][n+1]-sum)/A[i][i];
    }
    }

    void result(){
    cout<<"\nThe solution is: \n";
    for(i=1; i<=n; i++)
    {
cout<<"\nx"<<i<<" =  "<<x[i]<<"\t";
    }
    }

void display()
{
cout<<"\n The Matrix is :-\n ";
for(int i=1;i<=n;i++){
cout<<endl;
for(int j=1;j<=n+1;j++){
cout<<A[i][j]<<"     ";
}}
}

};

void main()
{
clrscr();
row obj;
obj.operation();
obj.display();
obj.result();
getch();

}


Sunday, February 1, 2015

GPA Calculator in JAVA


package usman1;
import java.util.Scanner;
public class Usman1 {
public static void main (String args[]){

  String grade = "";
  double credit1;
  double credit2;
  double credit3;
  double credit4;
  double gradeValue=0;
  double totPtsClass1=0;
  double totPtsClass2=0;
  double totPtsClass3=0;
  double totPtsClass4=0;
  double totPts=0;
  double totalCredits= 0;
  double gpa;

  Scanner console = new Scanner (System.in);
  System.out.println("Please enter the number of credits of the class 1 (A number)");
  credit1 = console.nextDouble();
  System.out.println("Please enter your grades for the class 1(Capital letters such as A,B+, C-)");
  grade = console.next();

  if (grade.equals ("A"))
    gradeValue= 4.00;
  else if (grade.equals("A-"))
    gradeValue= 3.67;
  else if (grade.equals("B+"))
    gradeValue = 3.33;
  else if (grade.equals("B"))
    gradeValue = 3.00;
  else if (grade.equals ("B-"))
    gradeValue = 2.67;
  else if (grade.equals("C+"))
    gradeValue = 2.33;
  else if (grade.equals("C"))
    gradeValue = 2.00;
  else if (grade.equals ("D+"))
  gradeValue = 1.33;
  else if (grade.equals ("D"))
    gradeValue = 1.00;
  else if (grade.equals ("F"))
    gradeValue = 0;
  else if (grade.equals ("FX"))
    gradeValue = 0;
  else
    System.out.println ("Invalid Grade");

  totPtsClass1 = gradeValue * credit1;

  System.out.println("Please enter the number of credits of the class 2 (A number)");
  credit2 = console.nextDouble();
  System.out.println("Please enter your grades for the class 2 (Capital letters such as A,B+, C-)");
  grade = console.next();

  if (grade.equals ("A"))
    gradeValue= 4.00;
  else if (grade.equals("A-"))
    gradeValue= 3.67;
  else if (grade.equals("B+"))
    gradeValue = 3.33;
  else if (grade.equals("B"))
    gradeValue = 3.00;
  else if (grade.equals ("B-"))
    gradeValue = 2.67;
  else if (grade.equals("C+"))
    gradeValue = 2.33;
  else if (grade.equals("C"))
    gradeValue = 2.00;
  else if (grade.equals ("D+"))
  gradeValue = 1.33;
  else if (grade.equals ("D"))
    gradeValue = 1.00;
  else if (grade.equals ("F"))
    gradeValue = 0;
  else if (grade.equals ("FX"))
    gradeValue = 0;
  else
  System.out.println ("Invalid Grade");

  totPtsClass2 = gradeValue * credit2;

  System.out.println("Please enter the number of credits of the class 3 (A number)");
  credit3 = console.nextDouble();
  System.out.println("Please enter your grades for the class 3 (Capital letters such as A,B+, C-)");
  grade = console.next();

  if (grade.equals ("A"))
    gradeValue= 4.00;
  else if (grade.equals("A-"))
    gradeValue= 3.67;
  else if (grade.equals("B+"))
    gradeValue = 3.33;
  else if (grade.equals("B"))
    gradeValue = 3.00;
  else if (grade.equals ("B-"))
    gradeValue = 2.67;
  else if (grade.equals("C+"))
    gradeValue = 2.33;
  else if (grade.equals("C"))
    gradeValue = 2.00;
  else if (grade.equals ("D+"))
  gradeValue = 1.33;
  else if (grade.equals ("D"))
    gradeValue = 1.00;
  else if (grade.equals ("F"))
    gradeValue = 0;
  else if (grade.equals ("FX"))
    gradeValue = 0;
  else
    System.out.println ("Invalid Grade");

    totPtsClass3 = gradeValue * credit3;

  System.out.println("Please enter the number of credits of the class 4 (A number)");
  credit4 = console.nextDouble();
  System.out.println("Please enter your grades for the class 4 (Capital letters such as A,B+, C-)");
  grade = console.next();

  if (grade.equals ("A"))
    gradeValue= 4.00;
  else if (grade.equals("A-"))
    gradeValue= 3.67;
  else if (grade.equals("B+"))
    gradeValue = 3.33;
  else if (grade.equals("B"))
    gradeValue = 3.00;
  else if (grade.equals ("B-"))
    gradeValue = 2.67;
  else if (grade.equals("C+"))
    gradeValue = 2.33;
  else if (grade.equals("C"))
    gradeValue = 2.00;
  else if (grade.equals ("D+"))
  gradeValue = 1.33;
  else if (grade.equals ("D"))
    gradeValue = 1.00;
  else if (grade.equals ("F"))
    gradeValue = 0;
  else if (grade.equals ("FX"))
    gradeValue = 0;
  else
    System.out.println ("Invalid Grade");
  totPtsClass4 = gradeValue * credit4;

  totPts= totPtsClass1+totPtsClass2+totPtsClass3+totPtsClass4;
  totalCredits = credit1+credit2+credit3+credit4;
  gpa= totPts / totalCredits;

  System.out.printf("Your GPA is: %.2f\n", + gpa);
}
}


Transpose Of A Matrix in C++

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10];
int b[10][10];
int row=0,col=0,i,j;
cout<<"\n Enter No of Rows And Colomn: ";
cin>>row>>col;
cout<<"\n Enter the values in matrix: (row by row) ";
for(i=1;i<=row;i++){
for(j=1;j<=col;j++){
cin>>a[i][j];
}}
for(i=1;i<=row;i++){
cout<<endl;
for(j=1;j<=col;j++){
cout<<a[i][j]<<"  \t";
}
}
for(i=1;i<=col;i++){
for(j=1;j<=row;j++){
b[j][i]=a[i][j];
} }
cout<<endl;
cout<<"\n Transpose Of The Matrix You Enter:-\n";
for(i=1;i<=row;i++){
cout<<endl;
for(int j=1;j<=col;j++){
cout<<b[i][j]<<"  \t";
}
}
getch();
      }

Another Screen Short of Code in C.