Monday, 12 November 2018

Logical vs. Physical Address Space

        Logical vs. Physical
                Address 

The concept of a logical address space that is bound to a
separate physical address space is central to proper 
memory management

Logical address – generated by the CPU; also referred to as virtual address

Physical address – address seen by the memory unit

Logical and physical addresses are the same in compile-time and load-time address-binding schemes;

 logical (virtual) and physical addresses differ in execution-time address-binding scheme

Logical address space is the set of all logical addresses generated by a program

Physical address space is the set of all physical addresses generated by a program

Sunday, 11 November 2018

java program:FIND AVERAGE OF MARKS

Q; Write a program in Java to find the average of marks obtained by a study in five papers.


Program:

import java.util.Scanner;   //FIRST IMPORT THE SCANNER CLASS FOR TAKING INPUT                                                  FROM USER 


public class Main  //main class always start with capital ex-public class Calculate
{
public static void main(String []args){

Scanner sc= new Scanner(System.in); //create a object of scanner class

double sum=0; 

double[] a = new double[100]; //declare a variable  of double data type for storing large floating value 

System.out.println("Enter the no of subject");

double s=sc.nextDouble(); //take input from user

System.out.println("Enter the marks");

for(int z=0;z<s;z++) //end start with 0 and end with size of number of subject
{

a[z]=sc.nextDouble();

sum=sum+a[z];

}

System.out.println("Average is"+sum/5);}

}


OUTPUT:


Enter the no of subject                                                                                                        
5                                                                                                                              
Enter the marks                                                                                                                
67 78 96 88 75                                                                                                                 
Average is80.8 

conversion of infix notation to postfix notation.in c++


Q: Write a program to demonstrate the use of stack in converting arithmetic
expression from infix notation to postfix notation.



PROGRAM: -


#include<iostream>
#include <string.h>
#include <stdlib.h>using namespace std;struct Stack
{
                        int top;
                        unsigned capacity;
                        int* array;
};


struct Stack* createStack( unsigned capacity )
{
                        struct Stack* stack = (struct Stack*) malloc(sizeof(struct Stack));
                        if (!stack)
                                    return NULL;
                        stack->top = -1;
                        stack->capacity = capacity;
                        stack->array = (int*) malloc(stack->capacity * sizeof(int));
                        if (!stack->array)
                                    return NULL;
                        return stack;
}


int isEmpty(struct Stack* stack)
{
                        return stack->top == -1 ;
}


char peek(struct Stack* stack)
{
                        return stack->array[stack->top];
}


char pop(struct Stack* stack)
{
                        if (!isEmpty(stack))
                                    return stack->array[stack->top--] ;
                        return '$';
}


void push(struct Stack* stack, char op)
{
                        stack->array[++stack->top] = op;
}


int isOperand(char ch)
{
                        return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
}


int Prec(char ch)
{
                        switch (ch)
                        {
                        case '+':
                        case '-':
                                    return 1;
                        case '*':
                        case '/':
                                    return 2;
                        case '^':
                                    return 3;
                        }
                        return -1;
}


int infixToPostfix(char* exp)
{
                        int i, k;
                        struct Stack* stack = createStack(strlen(exp));
                        if(!stack)                                    return -1 ;
                        for (i = 0, k = -1; exp[i]; ++i)
                        {
                                    if (isOperand(exp[i]))
                                                exp[++k] = exp[i];
                                    else if (exp[i] == '(')
                                                push(stack, exp[i]);
                                    else if (exp[i] == ')')
                                    {
                                                while (!isEmpty(stack) && peek(stack) != '(')
                                                            exp[++k] = pop(stack);
                                                if (!isEmpty(stack) && peek(stack) != '(')
                                                            return -1;                              
                                                else                                                            pop(stack);
                                    }
                                    else                                    {
                                                while (!isEmpty(stack) && Prec(exp[i]) <= Prec(peek(stack)))
                                                            exp[++k] = pop(stack);
                                                push(stack, exp[i]);
                                    }
                        }
                        while (!isEmpty(stack))
                                    exp[++k] = pop(stack );
                        exp[++k] = '\0';
                        cout<<"\npostfix is :-\n"<<exp;
}


int main()
{                        cout<<"Infix is :- \na+b*(c^d-e)^(f+g*h)-i\n";                        char exp[] = "a+b*(c^d-e)^(f+g*h)-i";                        infixToPostfix(exp);
                        return 0;
}



OUTPUT:

Infix is :-


a+b*(c^d-e)^(f+g*h)-i


postfix is :- 

abcd^e-fgh*+^*+i-          

Saturday, 10 November 2018

PROGRAM FOR QUICK SORT IN C++



Time    Complexity:


BestWorst
QuicksortΩ(n log(n))O(n^2)
MergesortΩ(n log(n))O(n log(n))
TimsortΩ(n)O(n log(n))

PROGRAM FOR QUICK SORT IN C++:


#include <iostream>
 using namespace std;

void quick_sort(int[],int,int);
int partition(int[],int,int);

int main()
{
    int a[50],n,i;
    cout<<"ENTER THE NUMBER OF ELEMENT";
    cin>>n;
    cout<<"\n ENTER ELEMENTS\n:";
    
    for(i=0;i<n;i++)
        cin>>a[i];
        
    quick_sort(a,0,n-1);
    cout<<"\n after sorting:";
    
    for(i=0;i<n;i++)
        cout<<a[i]<<" ";
    
    return 0;        
}

void quick_sort(int a[],int l,int u)
{
    int j;
    if(l<u)
    {
        j=partition(a,l,u);
        quick_sort(a,l,j-1);
        quick_sort(a,j+1,u);
    }
}

int partition(int a[],int l,int u)
{
    int v,i,j,temp;
    v=a[l];
    i=l;
    j=u+1;
    
    do
    {
        do
            i++;
            
        while(a[i]<v&&i<=u);
        
        do
            j--;
        while(v<a[j]);
        
        if(i<j)
        {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }while(i<j);
    
    a[l]=a[j];
    a[j]=v;
    
    return(j);
}

OUTPUT:


Thursday, 8 November 2018

how to find palindrome number in c,c++ and java

PALINDROME NUMBER:

Palindrome number is number remains the same after reversing the given number

Like 12312, for example, it is "symmetrical". The term palindromic is derived from palindrome, which refers to a word whose spelling is unchanged when its letters are reversed.

Ex:

aba after reverse the given word they will unchanged, 181, 191, 202

PROGRAM TO CHECK WHETHER THE GIVEN NUMBER IS PALINDROME NUMBER OR NOT IN C 



#include <stdio.h>

int main()
{



   int n, rev = 0, tem;
 


   printf("Enter a Number To Check Palindrome number\n");
   scanf("%d", &n);

   tem = n;

   while (tem != 0)
   {
      rev= rev * 10;


      rev= rev + tem%10; //first seperate last value by modulus of 10 ex:212%10=2


      tem = tem/10; seperate without last value so divede by 10 ex:212/10=21
   }

   if (n == rev) old vaue is same as new value then number is palindrome


      printf("%d is a palindrome number.\n", n);


   else


      printf("%d isn't a palindrome number.\n", n);

   return 0;
}

OUTPUT:
PROGRAM TO CHECK WHETHER THE GIVEN NUMBER IS PALINDROME NUMBER OR NOT IN C ++


#include <iostream>

using namespace std;
int main()
{

   int n, rev = 0, tem;
 

  cout<<"Enter a Number To Check Palindrome number\n"
 cin>>n;

   tem = n;

   while (tem != 0)
   {
      rev= rev * 10;


      rev= rev + tem%10;


      tem = tem/10;
   }

   if (n == rev)


    cout<<"is palindrome number";


   else


     cout<<" isn't a palindrome number"

   return 0;
}









PROGRAM TO CHECK WHETHER THE GIVEN NUMBER IS PALINDROME NUMBER OR NOT IN JAVA



import java.util.*;

class Palindrome    //java file name is same as class name

{

public static void main(String s[])

{Scanner in=new Scanner(System.in); //create a scanner class object to read the input from user

   int n, rev = 0, tem;
 

System.out.println("Enter a Number To Check Palindrome number\n")

 n=in.nextInt();

//read the integer value for float use in.nextFloat(); and for String use in.next()

   tem = n;

   while (tem != 0)
   {
      rev= rev * 10;


      rev= rev + tem%10;


      tem = tem/10;
   }

   if (n == rev)

System.out.println("is palindrome number");

   else

System.out.println("isn't a palindrome number");
}

}