Sunday, February 19, 2012

BinaryCalculator

//BinaryCalculator


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class BinaryCalculator extends JFrame
{
Container con;

int flag;
int num1 , num2;
int num3,num4;
char array1[];
int array[];

JTextArea txtop;
JButton butadd;
JButton butequ;
JButton butcomplement;
JButton butsub;
public BinaryCalculator()
{
con = this.getContentPane();
con.setLayout(null);

txtop = new JTextArea(1,15);
txtop.setBounds(50,50,300,30);
con.add(txtop);

butadd = new JButton("+");
butadd.setBounds(50,120,50,30);
con.add(butadd);

butsub = new JButton("-");
butsub.setBounds(125,120,50,30);
con.add(butsub);

butcomplement = new JButton("~");
butcomplement.setBounds(200,120,50,30);
con.add(butcomplement);

butequ = new JButton("=");
butequ.setBounds(275,120,50,30);
con.add(butequ);

butadd.addActionListener(new w11());
butsub.addActionListener(new w11());
butcomplement.addActionListener(new w11());
butequ.addActionListener(new w11());
}

class w11 implements ActionListener
{
String number;
int res;
public void actionPerformed(ActionEvent ae)
{
JButton temp = (JButton)ae.getSource();
if( temp.getLabel().equals("+") )
{
number = txtop.getText();
if( (res=chkbinary(number))==1 )
{
flag = 1;
num1 = getDecimal(number);
try
{
num3 = Integer.parseInt(number);
}
catch(Exception exc23)
{
JOptionPane.showMessageDialog(con,"number is not in range");
}


txtop.setText(null);
}
else
{
JOptionPane.showMessageDialog(con,"not a valid number");
txtop.setText(null);
}
}
else
if( temp.getLabel().equals("~") )
{
number = txtop.getText();
if( number.length() < 1 )
JOptionPane.showMessageDialog(con,"enter number");
else
{
flag = 2;
}
}

else
if( temp.getLabel().equals("-") )
{
number = txtop.getText();
if( (res = chkbinary(number) )==1 )
{
flag = 3;
num1 = getDecimal(number);
try
{
num3 = Integer.parseInt(number);
}
catch(Exception exc23)
{
JOptionPane.showMessageDialog(con,"number is not in range");
}

txtop.setText(null);
}
else
{
JOptionPane.showMessageDialog(con,"not a valid number");
txtop.setText(null);
}
}

else

if( temp.getLabel().equals("=") )
{
switch(flag)
{
case 1: number = txtop.getText();
if( (res=chkbinary(number) )==1 )
{
num2 = getDecimal(number);
int num5 = num1+num2;
txtop.setText(Integer.toBinaryString(num5));
}
else
{
JOptionPane.showMessageDialog(con,"not a valid number");
txtop.setText(null);
}
break;
case 3: number = txtop.getText();
if( (res=chkbinary(number) )==1 )
{
num2 = getDecimal(number);
int num5 = num1-num2;
txtop.setText(Integer.toBinaryString(num5));
}
else
{
JOptionPane.showMessageDialog(con,"not a valid number");
txtop.setText(null);
}
break; 
case 2:
number = txtop.getText();
txtop.setText(null);
if( ( res = chkbinary(number) )==1 )
{



for( int i = 0 ; i < number.length() ; i++ )
{
if( number.charAt(i) == '1')

array1[i] = '0';
else

array1[i] = '1'; 

txtop.append(Character.toString((char)array1[i])); 
}

}
else
{
JOptionPane.showMessageDialog(con,"not a valid number");
txtop.setText(null);
}
break;


default:System.out.println ("in default");break; 
}
}
}
public int getDecimal(String t)
{
int r, j=0;
int ans = 0;
array1 = t.toCharArray();
for( int i = (t.length()- 1); i >= 0 ; i--)
{

r = Integer.parseInt(""+t.charAt(i));
ans += r*(double)Math.pow((double)2,(double)j);
j++;
}
return ans;
}
public int chkbinary(String t)
{
array1 = t.toCharArray();

int i;
for( i = 0 ;i < t.length();i++)
{
if( array1[i] == '1' || array1[i] == '0')
{

}
else
break;
}

if( i == t.length())
return 1;
else return 0; 
}
}

public static void main(String arg[])
{
BinaryCalculator obj = new BinaryCalculator();
obj.setVisible(true);
obj.setTitle("Binary Calculator");
obj.setExtendedState(MAXIMIZED_BOTH);
obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}

C Program to find sum of digits of positive integer - c programs


C Program to find sum of digits of positive integer - c programs


//write a C Program to find sum of digits of positive integer
//print sum of digits of positive integer in / using c program




//C Program to print sum of digits of positive integer

#include<stdio.h>
#include<conio.h>
void main()
{
int num, k=1, sum=0;
clrscr();
printf(“Enter the number whose digits are to be added:”);
scanf(“%d”,&num);
while(num!=0)
{
k=num%10;
sum=sum+k;
k=num/10;
num=k;
}
printf(“Sum of the digits:%d”,sum);
getch();

C Program to print towers of hanoi - c programs


C Program to print towers of hanoi - c programs


//write a c program to print towers of hanoi
//Implement towers of hanoi using c language



what is towers of hanoi problem?

It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the puzzle is to move the entire stack to another rod, obeying the following rules: Only one disk may be moved at a time.
Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod.
No disk may be placed on top of a smaller disk.


//C Program to print towers of hanoi

#include <conio.h>
#include <stdio.h>
void main()
{
void hanoi(char,char,char,int);
char t1='A',t2='B',t3='C';
int n;
clrscr();
printf("\n Enter the no. of disks on Tower A:");
scanf("%d",&n);
if(n<1)
{
printf("\n Nothing to move");
}
else
hanoi(t1,t2,t3,n);
getch();
}
void hanoi(char t1,char t2,char t3,int n)
{
static int step=0;
step++;
printf("\n %c %c %c %d",t1,t2,t3,n);
if(n==1)
{
printf("\n Move top disk from Tower %c ----> %c",t1,t2);
return;
}
hanoi(t1,t3,t2,n-1);
printf("\n %c %c %c %d",t1,t2,t3,n);
printf("\n Move top disk from Tower %c ----> %c",t1,t2);
printf("\n %c %c %c %d",t1,t2,t3,n);
hanoi(t3,t2,t1,n-1);
printf("\n %c %c %c %d steps=%d",t1,t2,t3,n,step);
}

C Program to find a number is palindrome or not - c programs


C Program to find a number is palindrome or not - c programs



//C Program to find a number is palindrome or not
#include <stdio.h>
#include <conio.h>
main()
{
int n,t,s,r;
clrscr();
printf("enter any number");
scanf(%d",&n);
t=n;
s=0
while(n>0)
{
r=n%10;
s=(s*10)+r;
n=n/10;
}
if(t==s)
printf("%d is a palindrome number",t);
else
printf("%d is not a palindrome number",t);
gertch();
}

C Program to find a number is strong or not - c programs


C Program to find a number is strong or not - c programs


//C Program to find a number is strong or not
//eg: 145 is a strong number
#include <stdio.h>
#include <conio.h>
main()
{
int t,x,s,r;
clrscr();
printf("enter any number");
scanf(%d",&x);
t=x;
s=0
while(x>0)
{
r=x%10;
s=s*fact(r);
x=x/10;
}
if(t==s)
printf("%d is a strong number",t);
else
printf("%d is not a strong number",t);
gertch();
}
int fact(int a)
{
int f,g;
f=1;
for(g=a;g>0;g--)
f=f*g;
return(f);
}

C Program to find biggest of three numbers - c programs


C Program to find biggest of three numbers - c programs


//C Program to find biggest of three numbers

#include <stdio.h>
#include <conio.h>
main()
{
int a,b,c;
clrscr();
printf("enter any three numbers");
scanf(%d%d%d",&a, &b, &c);
if ((a>b) && (a>c))
printf("the biggest number is %d", a)
else if b>c
printf("the biggest number is %d", b)
else
printf("the biggest number is %d", c)
}

C Program to find largest and smallest value in an array - c programs


C Program to find largest and smallest value in an array - c programs


//C Program to find largest and smallest value in an array
#include <stdio.h>
#include <conio.h>
main()
{
int a[20];
int c,y,big,low;
clrscr();
printf("enter no of elements of array");
scanf("%d",&y);
printf("enter %d values", y)
for(c=0;c<y;c++)
{
printf("%d\t",a[c]);
big=0;
for(c=0;c<y;c++)
{
if(a[c]>big)
big=a[c];
if(a[c]<big)
low=a[c];
}
printf("\n the biggest value is %d", big);
printf("\n the smallest value is %d", low);
getch();
}

C Program to find no. of combinations - c programs

C Program to find no. of combinations - c programs


//C Program to find no. of combinations
#include <stdio.h>
#include <conio.h>
main()
{
int n,c,r;
clrscr();
printf("enter values of n amd r");
scanf("%d%d",&n,&r);
c=fact(n)/(fact(r)*Fact(n-r));
printf("No, of combinations of n and r ",c);
getch();
}
int fact(int a)
{
int f,g;
f=1;
for(g=a;g>0;g--)
f=f*g;
return(f);
}

C Program to find no. of digits in a number - c programs


C Program to find no. of digits in a number - c programs


//C Program to find no. of digits in a number
#include <stdio.h>
#include <conio.h>
main()
{
int a[20];
int c,y,big,low;
clrscr();
printf("enter no of elements of array");
scanf("%d",&y);
printf("enter %d values", y)
for(c=0;c<y;c++)
{
printf("%d\t",a[c]);
big=0;
for(c=0;c<y;c++)
{
if(a[c]>big)
big=a[c];
if(a[c]<big)
low=a[c];
}
printf("\n the biggest value is %d", big);
printf("\n the smallest value is %d", low);
getch();
}

C Program to find no. of permutations - c programs


C Program to find no. of permutations - c programs


//C Program to find no. of permutations
#include <stdio.h>
#include <conio.h>
main()
{
int n,c,r;
clrscr();
printf("enter values of n amd r");
scanf("%d%d",&n,&r);
c=fact(n)/Fact(n-r);
printf("No, of permutations of n and r ",c);
getch();
} int fact(int a)
{
int f,g;
f=1;
for(g=a;g>0;g--)
f=f*g;
return(f);
}

C Program to find prime numbers below 100 - c programs


C Program to find prime numbers below 100 - c programs


//C Program to find prime numbers below 100
#include <stdio.h>
#include <conio.h>
main()
{
int n;
clrscr();
printf("enter any number");
scanf(%d",&n);
printf(“ PRIME NUMBERS ARE below %d are…: “, n);
for(i=1; i<n; i++)
{
prime = 1;
for(j=2; j<i; j++)
if(i%j == 0)
{
prime = 0;
break;
}
if(prime)
printf(“%d”,n);
}
getch();
}

C Program to find result of power value - c programs


C Program to find result of power value - c programs


//C Program to find result of power value
#include <stdio.h>
#include <conio.h>
main()
{
int x,y,p;
clrscr();
printf("enter values of x amd y");
scanf("%d%d",&x,&y);
p=pow(x,y);
printf("the result of x to power y is ",p);
getch();
}

C Program to find reverse of a number - c programs


C Program to find reverse of a number - c programs


//C Program to find reverse of a number
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int r=0,d,m,n;
printf("Enter a number:");
scanf("%d",&n);
m=n;
do
{
d=m%10;
m= m/10;
r=(r*10)+d;
}
while(m!=0);
printf("%d is the reverse of number\n",r);
}
getch();
}


C Program to find smallest number in an array - c programs


C Program to find smallest number in an array - c programs


//C Program to find smallest number in an array
#include <stdio.h>
#include <conio.h>
main()
{
int a[10],i,small;
clrscr();
printf("enter the numbers in an array");
for(i=0;i<10;i++)
scanf(%d%d%d",&a[i]);
small=a[0];
for(i=0;i<n;i++)
{
if(small>a[i])
{
small=a[i];
}
}
printf("the smallest number is ",small);
}
}

C Program to find sum of digits of a number - c programs

C Program to find sum of digits of a number - c programs


//C Program to find sum of digits of a number
#include<stdio.h>
#include<conio.h>
void main()
{
int a,n,sum=0;
clrscr();
printf("Enter the number"); scanf("%d",&a);
do
{
n=a%10;
sum=sum+n;
a=a/10;
}
while(a=0);
printf("The sum of digits of the number %d is %d",a,sum);
getch();
}

C Program to implement Floyd's triangle - c program


C Program to implement Floyd's triangle - c program


//C Program to implement Floyd's triangle

#include <stdio.h>
#include <conio.h>
main()
{
int i,j,t,rows;
clrscr();
printf("enter the no, of rows");
scanf("%d",&rows);
t=1;
for(i=0;i<rows;i++)
{
for(j=0;j<=i;j++)
{
printf("%d \t", t)
t++
}
printf("\n")
}
getch();
}

C Program to show if a number is even or odd - c programs


C Program to show if a number is even or odd - c programs


//C Program to show if a number is even or oddd

#include <stdio.h>
#include <conio.h>
main()
{
int n;
clrscr();
printf("enter any number");
scanf(%d",&n);
if(n%2==0)
printf("number is even");
else
printf("number is odd");
getch();
}

C Program to swap two numbers without using temp variable - c programs


C Program to swap two numbers without using temp variable - c programs


//C Program to swap two numbers without using temp variable
#include <stdio.h>
#include <conio.h>
main()
{
int a,b;
clrscr();
printf("enter two numbers");
scanf("%d%d",&a, &b);
printf("the value of a is %d" ,a);
printf("the value of b is %d" ,b);
a=a+b;
b=a-b;
a=a-b;
printf("the value of a after swapping is %d" ,a);
printf("the value of b after swapping is %d" ,b);
getch();
}

C Program to print numbers in word format - c programs


C Program to print numbers in word format - c programs


//write a C Program to print numbers in word format
// convert number to word format in c
// display number in word format using c program



//C Program to print numbers in word format

#include<stdio.h>
void pw(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","
eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","
fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","
seventy"," eighty"," ninety"};
void main()
{
long n;
clrscr();
printf("
Enter any 9 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else

pw((n/10000000),"crore");
pw(((n/100000)%100),"lakh");
pw(((n/1000)%100),"thousand");
pw(((n/100)%10),"hundred");
pw((n%100)," ");
}
getch();
}
void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}

C Program to print pascals triangle - c programs


C Program to print pascals triangle - c programs


//Write a c program to print pascals triangle
//Display pascals triangle in c language
//Generate pascals triangle using c



//C Program to print pascals triangle

#include<stdio.h>
#include<conio.h>
void main(){
int a[15][15],i,j,rows,num=25,k;
printf("Pascal's Triangle:"); 
printf("\n enter the number of rows:");
scanf("%d",&rows);
for(i=0;i<rows;i++){
for(k=num-2*i;k>=0;k--)
printf(" "); 
for(j=0;j<=i;j++){
if(j==0||i==j){
a[i][j]=1;
}
else{
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
printf("%4d",a[i][j]);
}
printf("\n");
}
getch();
}

OUTPUT:
Pascal's Triangle:
enter the number of rows:3
       1
      1 1
     1 2 1

C Program to find roots of quadriatic expression - c programs

C Program to find roots of quadriatic expression - c programs



//write a c program to find roots of quadriatic expression
//roots of quadriatic expression in / using c language





//C Program to find roots of quadriatic expression

#include<stdio.h>
void main()
{
int a,b,c,d;
float root1,root2;
printf("Enter the values of a,b,c");
scanf("%d%d%d",&a,&b,&c);
d=b*b-4*a*c;
root1=((-b)+sqrt(d))/(2*a);
root2=((-b)-sqrt(d))/(2*a);
printf("The roots of quadriatic expression are");
printf("root1=%f and root2=%f",root1,root2);
}


//Nature of roots of quadriatic expression

#include<stdio.h>
#include<math.h>
void main()
{
int A, B, C;
float d,deno,x1, x2;
clrscr();
printf("\n\n\t ENTER THE VALUES OF A,B,C...");
scanf("%d,%d,%d", &A, &B, &C);
d = (B * B) - (4 * A * C);
deno = 2 * A;
if(d > 0)
{
printf("\n\t THE ROOTS ARE REAL ROOTS");
x1 = (-B/deno) + (sqrt(d / deno);
x2 = (-B/deno) - (sqrt(d) / deno);
printf("\n\n\t THE ROOTS ARE...: %f and %f\n", x1, x2);
}
else if(d == 0)
{
printf("\n\t THE ROOTS ARE IDENTICAL ROOTS");
x1 = -B/deno;
printf("\n\n\t THE ROOT IS...: %f\n", x1);
}
else
printf("\n\t THE ROOTS ARE IMAGINARY ROOTS\n");
getch();

C Program to find addition and subtraction of complex numbers - c programs


C Program to find addition and subtraction of complex numbers - c programs


Write a C Program to find addition and subtraction of complex numbers - add two complex numbers using c - subtract two complex numbers in c language 

//Write a C Program to find addition and subtraction of complex numbers - add two complex numbers using c - subtract two complex numbers in c language

#include<stdio.h>
int main(){
int a,b,c,d,x,y;
printf("\nEnter the first complex number:");
scanf("%d%d",&a,&b);
printf("\nEnter the second complex number:");
scanf("%d%d",&c,&d);
if(b<0)
printf("%d-i\n",a-b);
else
printf("d+i\n",a+b);
if(d<0)
printf("d-i\n",c-d);
else
printf("%d+i\n",c+d);
printf("\nADDITION ");
x=a+c;
y=b+d;
if(y>0)
printf("%d-i%d",x,-y);
else
printf("%d+i%d",x,+y);
printf("\n\nSUBTRACTION ");
x=a-c;
y=b-d;
if(y<0)
printf("%d-i%d",x,-y);
else
printf("%d+i%d",x,+y);
return 0;
}

Slider

Image Slider By engineerportal.blogspot.in The slide is a linking image  Welcome to Engineer Portal... #htmlcaption

Tamil Short Film Laptaap

Tamil Short Film Laptaap
Laptapp

Labels

About Blogging (1) Advance Data Structure (2) ADVANCED COMPUTER ARCHITECTURE (4) Advanced Database (4) ADVANCED DATABASE TECHNOLOGY (4) ADVANCED JAVA PROGRAMMING (1) ADVANCED OPERATING SYSTEMS (3) ADVANCED OPERATING SYSTEMS LAB (2) Agriculture and Technology (1) Analag and Digital Communication (1) Android (1) Applet (1) ARTIFICIAL INTELLIGENCE (3) aspiration 2020 (3) assignment cse (12) AT (1) AT - key (1) Attacker World (6) Basic Electrical Engineering (1) C (1) C Aptitude (20) C Program (87) C# AND .NET FRAMEWORK (11) C++ (1) Calculator (1) Chemistry (1) Cloud Computing Lab (1) Compiler Design (8) Computer Graphics Lab (31) COMPUTER GRAPHICS LABORATORY (1) COMPUTER GRAPHICS Theory (1) COMPUTER NETWORKS (3) computer organisation and architecture (1) Course Plan (2) Cricket (1) cryptography and network security (3) CS 810 (2) cse syllabus (29) Cyberoam (1) Data Mining Techniques (5) Data structures (3) DATA WAREHOUSING AND DATA MINING (4) DATABASE MANAGEMENT SYSTEMS (8) DBMS Lab (11) Design and Analysis Algorithm CS 41 (1) Design and Management of Computer Networks (2) Development in Transportation (1) Digital Principles and System Design (1) Digital Signal Processing (15) DISCRETE MATHEMATICS (1) dos box (1) Download (1) ebooks (11) electronic circuits and electron devices (1) Embedded Software Development (4) Embedded systems lab (4) Embedded systems theory (1) Engineer Portal (1) ENGINEERING ECONOMICS AND FINANCIAL ACCOUNTING (5) ENGINEERING PHYSICS (1) english lab (7) Entertainment (1) Facebook (2) fact (31) FUNDAMENTALS OF COMPUTING AND PROGRAMMING (3) Gate (3) General (3) gitlab (1) Global warming (1) GRAPH THEORY (1) Grid Computing (11) hacking (4) HIGH SPEED NETWORKS (1) Horizon (1) III year (1) INFORMATION SECURITY (1) Installation (1) INTELLECTUAL PROPERTY RIGHTS (IPR) (1) Internal Test (13) internet programming lab (20) IPL (1) Java (38) java lab (1) Java Programs (28) jdbc (1) jsp (1) KNOWLEDGE MANAGEMENT (1) lab syllabus (4) MATHEMATICS (3) Mechanical Engineering (1) Microprocessor and Microcontroller (1) Microprocessor and Microcontroller lab (11) migration (1) Mini Projects (1) MOBILE AND PERVASIVE COMPUTING (15) MOBILE COMPUTING (1) Multicore Architecute (1) MULTICORE PROGRAMMING (2) Multiprocessor Programming (2) NANOTECHNOLOGY (1) NATURAL LANGUAGE PROCESSING (1) NETWORK PROGRAMMING AND MANAGEMENT (1) NETWORKPROGNMGMNT (1) networks lab (16) News (14) Nova (1) NUMERICAL METHODS (2) Object Oriented Programming (1) ooad lab (6) ooad theory (9) OPEN SOURCE LAB (22) openGL (10) Openstack (1) Operating System CS45 (2) operating systems lab (20) other (4) parallel computing (1) parallel processing (1) PARALLEL PROGRAMMING (1) Parallel Programming Paradigms (4) Perl (1) Placement (3) Placement - Interview Questions (64) PRINCIPLES OF COMMUNICATION (1) PROBABILITY AND QUEUING THEORY (3) PROGRAMMING PARADIGMS (1) Python (3) Question Bank (1) question of the day (8) Question Paper (13) Question Paper and Answer Key (3) Railway Airport and Harbor (1) REAL TIME SYSTEMS (1) RESOURCE MANAGEMENT TECHNIQUES (1) results (3) semester 4 (5) semester 5 (1) Semester 6 (5) SERVICE ORIENTED ARCHITECTURE (1) Skill Test (1) software (1) Software Engineering (4) SOFTWARE TESTING (1) Structural Analysis (1) syllabus (34) SYSTEM SOFTWARE (1) system software lab (2) SYSTEMS MODELING AND SIMULATION (1) Tansat (2) Tansat 2011 (1) Tansat 2013 (1) TCP/IP DESIGN AND IMPLEMENTATION (1) TECHNICAL ENGLISH (7) Technology and National Security (1) Theory of Computation (3) Thought for the Day (1) Timetable (4) tips (4) Topic Notes (7) tot (1) TOTAL QUALITY MANAGEMENT (4) tutorial (8) Ubuntu LTS 12.04 (1) Unit Wise Notes (1) University Question Paper (1) UNIX INTERNALS (1) UNIX Lab (21) USER INTERFACE DESIGN (3) VIDEO TUTORIALS (1) Virtual Instrumentation Lab (1) Visual Programming (2) Web Technology (11) WIRELESS NETWORKS (1)

LinkWithin