Posts

Conversion Of Big Number into Words(In Indian System).

package snlkjha; import java.util.*; import java.math.BigInteger; /**  * @author snlkjha  */ public class N2word {     public static String get(int n){         String[] x1={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thrteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Ninteen"};         String[] x2={"","Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninty","Hundred"};         if(n<20) return x1[n];         else return x2[n/10]+" "+x1[n%10];     }       public static String convert_number_into_words(BigInteger n){       String message=" Only",x3[]={"",...

Program for finding Body Mass Index Using JAVA

/*  * BODY MASS INDEX  * It is a numeric indicator of human body fat based on a person weight and height.It is applicable to adult men  * and women and is mainy used to screen indivduals in order to detect potential weight problems.  * The common formulafor calculating BMI = Mass(Kg)/[height(m)]^2  * It was invented by Begian Scinetist Adolphe Quetelet and hence it is also known as the Quetelet Index.  * A BMI of 18.5 to 24.9 is considered normal.  */ package Snlkjha; import javax.swing.*; /**  * @author Snlkjha  */ public class BodyMassIndex {     public static void main(String[] args) {                 String wt = JOptionPane.showInputDialog("Enter Weight(In Kg):");         String ht = JOptionPane.showInputDialog("Enter Height(In Inch):");         double weight = Double.valueOf(wt).doubleValue();         double...

STRING PALINDROME USING STACK AND QUEUE

#include<stdio.h> #include<stdlib.h> #include<string.h> void push(char ); char pop(); void nq(char ); char dq(); typedef struct list {     char data;     struct list *next; }node; node *top=NULL,*front=NULL,*rear=NULL; int main() {     char word[20];     printf("Type the Word:");     scanf("%s",word);     int length=strlen(word),i=0;     while(word[i]!='\0')     {         push(word[i]);         nq(word[i]);         i++;     }     for(i=0;i<length;i++)     {         if(pop()!=dq())         break;             }     if(i==length)        ...

PROLOG ASSIGNMENT 3 (SAU).(MIN_COST)

path_C(A, Z, Graph, Path, Cost) :-           path1_C(A, [Z], 0, Graph, Path, Cost). path1_C(A, [A|Path1], Cost1, Graph, [A|Path1], Cost1). path1_C(A, [Y|Path1], Cost1, graph(Nodes, Edges), Path, Cost) :-           (member(e(X,Y,CostXY), Edges); member(e(Y,X,CostXY), Edges)),            not (member(X, Path1)),           Cost2 is Cost1 + CostXY,           path1_C(A, [X,Y|Path1], Cost2, graph(Nodes, Edges), Path, Cost). shortest_path(A, Z, Graph, Path, Mini_Cost) :-          path_C(A, Z, Graph, Path, Mini_Cost),          no_shorter_path(A, Z, Graph, Path1, Cost1, Mini_Cost). no_shorter_path(A, Z, Graph, Path, Cost, Mini_Cost) :-        ...

PROLOG ASSIGNMENT 3 (SAU).

path(A, Z, Graph, Path) :-           path1(A,[Z],Graph,Path). path1(A, [A|Path1], Graph, [A|Path1]). path1(A, [Y|Path1], graph(Nodes, Edges), Path) :-                 (member(e(X,Y), Edges); member(e(Y,X), Edges)),                 not (member(X, Path1)),                        path1(A, [X,Y|Path1], graph(Nodes, Edges), Path). member(X, [X|L]). member(X, [Y|L]) :-     member(X, L). eq_set(P, N) :-     subset(P,N),     subset(N,P). subset([],[]). subset( [X|Set],Subset)  :-            % X not in subset   subset(Set,Subset). subset( [X|Set],[X|Subset])  :-      % X included in subset   subset(...

MATRIX MULTIPLICATION

Q. Write a program that contains three functions, the first two will be encoder and decoder function used to decode and encode a matrix of integers.The encoder will simply swap the values of elements A ij and A ji. The decoder will unswapp the values,So for example A 12 will be swapped with A 21during encoding and back during decoding.Write the third function to multiply three matrices. Now a data file will be in the following formate <'E or D'><N rows><M column><A 11A 12A 13....AN rowsM columns> The first character of the file will be either E or D indicating whether the data is encoded or decoded. The following integers indicate the number of rows and columns,followed by matrix data. Write a program to read two encoded files (Say M1.dat M2.dat) and multiply them to generate a third encoded file (say M3.dat) in the exact same formatedescribed above.use command line argument. So to run it with the above three files I should type ./a.out M1.dat M2.dat ...

Histogram

#include<stdio.h> int main() { int a[]={1,2,1,3,5,4,3,2,1,2,3,1,4,5,3,2,1,6,5,2,2,1,1}; histogram(a,23); return 0; } int histogram(int a[],int n){ int i,j,k=0,l,m=0,count[25]={0},max=0; for(i=0;i<n;i++){ for(j=0;j<n;j++){ if(a[i]==a[j]) count[i]++; //counting the occurance of each element in the array } int flag=0; for(j=0;j<i;j++) if(a[i]==a[j]) flag=1; // removing redundant element //====================displaying histogram1===================*/ if(!flag) { a[m]=a[i]; count[m]=count[i]; max=max<count[m]?count[m]:max; m++; printf("%d %d ",a[i],count[i]); for(k=0;k<count[i];k++) printf("*"); printf("\n"); } } printf("=================displaying histogram2==================\n"); for(i=0;i<m;i++) { for(l=0;l<max-count[i];l++) printf("\t"); for(j=0;j<count[i];j++) printf("*\t"); printf(...