Search

12 May, 2016

PRIME NUMBERS WITH IN THE GIVEN RANGE

#include<iostream>
#include<iomanip>
using namespace std;

int main(){
    int num,i,count,n;
    cout << "Enter max range: ";
    cin >> n;
    for(num = 1;num<=n;num++){
         count = 0;
         for(i=2;i<=num/2;i++){
             if(num%i==0){
                 count++;
                 break;
             }
        }
       
         if(count==0 && num!= 1)
              cout << num << setw(3);
    }
 system("pause");
   return 0;
}

Sort Elements in Lexicographical Order

#include<iostream>
#include <cstring>
using namespace std;
int main(){
    int i,j;
    char str[10][50],temp[50];
    cout << "Enter 10 words: " << endl;
    for(i=0;i<10;++i)
        cin.getline(str[i], 50);
    for(i=0;i<9;++i)
       for(j=i+1;j<10 ;++j){
          if(strcmp(str[i],str[j])>0)
          {
            strcpy(temp,str[i]);
            strcpy(str[i],str[j]);
            strcpy(str[j],temp);
          }
    }
    cout << "In lexicographical order: " << endl;
    for(i=0;i<10;++i){
       cout << str[i] << endl;
    }
return 0;
}

Enter 10 words:
fortran
java
perl
python
php
javascript
c 
cpp
ruby
csharp

In lexicographical order:
c
cpp
csharp
fortran
java
javascript
perl
php
python
ruby

11 May, 2016

Cache memory

A Cache (Pronounced as “cash”) is a small and very fast temporary storage memory. It is designed to speed up the transfer of data and instructions. It is located inside or close to the CPU chip. It is faster than RAM and the data/instructions that are most recently or most frequently used by CPU are stored in cache.
The data and instructions are retrieved from RAM when CPU uses them for the first time. A copy of that data or instructions is stored in cache. The next time the CPU needs that data or instructions, it first looks in cache. If the required data is found there, it is retrieved from cache memory instead of main memory. It speeds up the working of CP