Skip to main content

Posts

Showing posts from October, 2011

Sample: Calculation Factorial by Recursive Method

#include<stdio.h> int fact(int s) {     int x,y;     if(s==0)     {         return(1);     }else         {             x=s-1;             y=fact(x);             return(s*y);         }     } int main() {     int i;     printf("\nEnter No");     scanf("%d",&i);     printf("\nResult:: %d",fact(i)); }

Binary Search Operation With the use of Recursive Function

#include<stdio.h> #define MAX 5 int a[MAX]; insert() {     int i;     for(i=0;i<=MAX;i++)     {         printf("\nEnter No :: ");         scanf("%d",&a[i]);     } } sort() {     int i,j,temp;     for(i=0;i<=MAX;i++)     {         for(j=i;j<=MAX;j++)         {             if(a[i]>a[j])             {                 temp=a[j];                 a[j]=a[i];                 a[i]=temp;             }         }     } } display() {     int i;     for(i=0;i<=MAX;i++)     {         printf("\t%d",a[i]);     } } binarySearch(int low,int high,int value) {     int mid;     mid=(low+high)/2;     if((mid==0 &&  (a[mid]!=value)) || (mid==MAX && (a[mid]!=value)))     {         printf("\nRecord Not Found");     }     else if(a[mid]==value)     {         printf("record found");     }else{             if(value<a[mid])             {                 binarySearch(0,mid,value);             }else{                     bi

Sample: A Java Applet Program to Calculate Summation of two numbers

import java.awt.*; import java.applet.*; public class user extends Applet {     TextField t1,t2; // Declaring Object variables     public void init() // Initializing Objects     {         t1=new TextField(10);         t2=new TextField(10);         add(t1);         add(t2);         t1.setText("0.00");         t2.setText("0.00");     }     public void paint(Graphics g) // Drawing Objects On The Java Form     {         int x=0,y=0,z=0;         String s1,s2,s;         g.drawString("Input A number in Each Box",10,50);         try         {             s1=t1.getText();             x=Integer.parseInt(s1);             s2=t2.getText();             y=Integer.parseInt(s2);         }catch(Exception e)         {             System.out.println(e.getMessage());         }         z=x+y;         s=String.valueOf(z);         g.drawString("THE SUM IS :: ",10,75);         g.drawString(s,100,75);     }     public boolean action(Event e,Object o) //On Enter Key Press

Example of Reversed Link List Operation in C

#include<stdio.h> #include<malloc.h> typedef struct list { int data; struct list *next; }node; node *START=NULL; insert() { int i;     node *tmp,*q;     tmp=(node*)malloc(sizeof(node)); printf("\nEnter Element :: "); scanf("%d",&i);     tmp->next=NULL;     tmp->data=i;     if(START==NULL)     {         START=tmp;     }else         {             q=START;             while(q->next!=NULL)             {                 q=q->next;             }             q->next=tmp;         } } display() { node *q; if(START==NULL) { printf("\nList Is Empty"); }else{ q=START; while(q!=NULL) { printf("%d -> ",q->data); q=q->next; } } }  reverse() { node *p1,*p2,*p3; int d; if(START==NULL) { printf("\nThis Opetation Is Not Possible Due to Lack of Elements"); } else { p1=START; p2=p1->next; p3=p2->next;

Sample : String Reverse In Java

import java.io.*; class test {     public static void main(String args[])     {         DataInputStream in=new DataInputStream(System.in);         try         {             String text;             System.out.println("\nEnter The Text");             text=in.readLine();             System.out.println("\nIn Reverse Order::\n");             for(int i=text.length()-1;i>=0;i--)             {                 System.out.print(text.charAt(i));             }             System.out.println("\n");         }catch(Exception e)         {             System.out.println("\nError in Input");         }     } }

Sample: Dual Directional Linked List

#include<stdio.h> #include<malloc.h> typedef struct list {     int data;     struct list *lnext;     struct list *rnext; }node; node *START=NULL; insert() {     int i,f;     node *tmp,*q;     tmp=(node*)malloc(sizeof(node));     printf("Enter a value");     scanf("%d",&i);     tmp->data=i;     if(START==NULL)     {         START=tmp;     }else     {         printf("Enter SIDE 1. Right 2. Left");         scanf("%d",&f);         if(f==1)         {             q=START;             while(q->rnext!=NULL)             {                 q=q->rnext;             }             q->rnext=tmp;         }else if(f==2)         {             q=START;             while(q->lnext!=NULL)             {                 q=q->lnext;             }             q->lnext=tmp;         }else{printf("Invalid Input");}     }     } display() {     node *q;     if(START==NULL)         printf("Empty List");     else    

Internet and Network Connection in Linux System

1. LAN (Wired) 2. Wireless 3. Mobile Broadband +-+-+-+-+-+-+-+-+-+-+-+-+-+- 1. Wired (LAN) +-+-+-+-+-+-+-+-+-+-+-+-+-+-     Manually entering your network settings:     If you don't have DHCP on your network then you can configure a static         connection. You will need to enter the network settings yourself, so         check with your network administrator or look at your router's         settings to find out which details to use.    1.Right click the Network Manager icon in the system notification area and click Edit Connections.       2.Click the Wired tab, select the connection and click Edit.           3.Click the IPv4 Settings tab and choose Manual from the Method drop down list.         4.Click Add and enter your IP address and other details. Enter the address of your DNS server too. 5.Click Apply. The network should now connect if you entered the settings correctly. +-+-+-+-+-+-+-+-+-+-+-+- 2. Wireless +-+-+-+-+-+-+-+-+-+-+-+- To conn

Basic Link List Operations

//Basic Link List Operation #include<stdio.h> #include<malloc.h> typedef struct list {     int data;     struct list *next; }node; int count=0; node *START=NULL; insert(int i) {     node *tmp,*q;     tmp=(node*)malloc(sizeof(node));     tmp->next=NULL;     tmp->data=i;     if(START==NULL)     {         START=tmp;         count++;     }else         {             q=START;             while(q->next!=NULL)             {                 q=q->next;             }             q->next=tmp;             count++;         } } display() {     node *q;     if(START==NULL)     {         printf("\nList IS Empty");     }else         {             q=START;             while(q!=NULL)             {                 printf("\t%d",q->data);                 q=q->next;             }         }     } int search(int i) {     int flag=0;     node *q;     if(START==NULL)     {         printf("\nList IS Empty");     }else         {             q=START

Circular Queue in C language

//Circular Queue in C language #include<stdio.h> #define MAX 5 int queue[MAX]; int front=-1; int rear=-1; insert() {     int i;     if((rear==MAX-1 && front==0) || (front==rear+1))     {         printf("\nQueue is FUll");     }     else     {         printf("\nEnter an element:: ");         scanf("%d",&i);                 if(front==-1)         {             front=0;         }         if(rear==MAX-1)         {             rear=0;         }else         {             queue[++rear]=i;         }     }         } delete() {     if(front==-1)     {         printf("Queue is empty");     }     else     {         printf("%d has deleted",queue[front]);         if(front==rear)         {             front=rear=-1;         }else         {             if(front==MAX-1)             {                 front=0;             }else             {                 front++;             }         }     } } int main() {     int ch,f=0;     //clrs

Queue in C Language

//Simple Queue Implementation In C language #include<stdio.h> #define MAX 5 int front=-1; int rear=-1; int queue[MAX]; insert() {     int i;     if(rear==(MAX-1))     {         printf("\nQueue Overflowed!");     }else         {             printf("\nEnter A Value::");             scanf("%d",&i);             queue[++rear]=i;             if(front==-1)             {                 front=0;             }         } } delete() {     int i;     if(rear==-1)     {         printf("\nQueue is empty");     }else         {             if(front==rear)             {                 printf("\nQueue Has Lack Of Elements To Delete");             }else{                     i=queue[front];                     printf("%d has removed",i);                     front++;                 }         } } clear() {     int ch;     printf("Are you sure to clear the QUEUE? Yes (1) or No (2)");     scanf("%d",&ch);     swi

Basic Stack Operation In C Language

// 1. BASIC STACK OPERATION OVER 1D ARRAY #include<stdio.h> #include<conio.h> #define MAX 4 int top=-1; int stack[MAX]; void push() { int i; printf("\nEnter A Number To Store it Into Current Stack:: "); scanf("%d",&i); if(top==MAX) { printf("\nSorry Stack is FULL"); }else { stack[++top]=i; printf("\nNumber Added!!!"); } } void pop() { if(top==-1) { printf("\nStack is empty!"); }else{ printf("\nTOP value is :: %d",stack[top--]); printf("\nOne Value Popped"); } } void main() { int ch,f=0; clrscr(); while(f<=1) { printf("\n1. ADD VALUE\n2. POP VALUE\n3. EXIT"); scanf("%d",&ch); switch(ch) { case 1: push(); getch(); break; case 2: pop(); getch(); break; case 3: exit(); default: printf("\nWrong Input"); } } } //2. BASIC STACK O

Using the mod() function with negative numbers

Using the mod() function with negative numbers     There are different ways of thinking about remainders when you deal with negative numbers, and he is probably confusing two of them. The mod function is defined as the amount by which a number exceeds the largest integer multiple of the divisor that is not greater than that number. In this case, -340 lies between -360 and -300, so -360 is the greatest multiple LESS than -340; we subtract 60 * -6 = -360 from -340 and get 20:     -420 -360 -300 -240 -180 -120 -60 0 60 120 180 240 300 360 --+----+----+----+----+----+----+----+----+----+----+----+----+----+-- | | | | -360| |-340 300| |340 |=| |==| 20 40 Working with a positive number like 340, the multiple we subtract is smaller in absolute val

A simple java threading example...

class A extends Thread {         public void run()         {                 for(int i=1;i<=5;i++)                 {                         if (i==1) yield();                           System.out.println("\tFrom Thread A : i = "+i);                 }                 System.out.println("\nExit from A");         } } class B extends Thread {         public void run()         {                 for(int j=1;j<=5;j++)                 {                         if (j==3) stop();                           System.out.println("\tFrom Thread A : j = "+j);                 }                 System.out.println("\nExit from B");         } } class C extends Thread {         public void run()         {                 for(int k=1;k<=5;k++)                 {                         if (k==1)                         try{                                 sleep(1000);                             }catch(Exception e)        

Searching BOOLEAN on the INTERNET

A Primer in Boolean Logic The Internet is a vast computer database. As such, its contents must be searched according to the rules of computer database searching. Much database searching is based on the principles of Boolean logic. Boolean logic refers to the logical relationship among search terms, and is named for the British-born Irish mathematician George Boole. On Internet search engines, the options for constructing logical relationships among search terms often modify the traditional practice of Boolean searching. This will be covered in the section below, Boolean Searching on the Internet. Boolean logic consists of three logical operators: OR AND NOT Each operator can be visually described by using Venn diagrams, as shown below. OR logic college OR university Question: I would like information about college. In this search, we will retrieve records in which AT LEAST ONE of the search terms is present. We are searching on the terms college and also