Thursday, October 20, 2011

C++ program to print matrix difference


//C++ program to subtract two matrices
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int matrix1[3][4],matrix2[3][4],matrix3[3][4];
int i,j;
cout<<"\nEnter numbers to fill matrix 1\n";
for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
   cin>>matrix1[i][j];
  }
}
cout<<"\nEnter numbers to fill matrix 2\n";
for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
   cin>>matrix2[i][j];
  }
}

cout<<"Original Matrix 1:\n";
for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
   cout<<matrix1[i][j]<<" ";
  }
 cout<<"\n";
}
cout<<"\n\nOriginal Matrix 2:\n";

for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
   cout<<matrix2[i][j]<<" ";
  }
cout<<"\n";
}
cout<<"\n\nDifference of Matrix 1 and Matrix 2:\n";

for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
   matrix3[i][j]=matrix1[i][j]-matrix2[i][j];
   cout<<matrix3[i][j]<<" ";
  }
cout<<"\n";
}

getch();
}

C++ program to print sum of two matrices


//C++ program to sum two matrices
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int matrix1[3][4],matrix2[3][4],matrix3[3][4];
int i,j;
cout<<"\nEnter numbers to fill matrix 1\n";
for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
   cin>>matrix1[i][j];
  }
}
cout<<"\nEnter numbers to fill matrix 2\n";
for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
   cin>>matrix2[i][j];
  }
}

cout<<"Original Matrix 1:\n";
for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
   cout<<matrix1[i][j]<<" ";
  }
 cout<<"\n";
}
cout<<"\n\nOriginal Matrix 2:\n";

for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
   cout<<matrix2[i][j]<<" ";
  }
cout<<"\n";
}
cout<<"\n\nSum of Matrix 1 and Matrix 2:\n";

for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
   matrix3[i][j]=matrix1[i][j]+matrix2[i][j];
   cout<<matrix3[i][j]<<" ";
  }
cout<<"\n";
}

getch();
}

C program to print transpose matrix


//C++ program to print transpose of a matrix
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int matrix[3][4],transpose_matrix[4][3];
int i,j;
cout<<"\nEnter numbers to fill matrix\n";
for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
   cin>>matrix[i][j];
   transpose_matrix[j][i]=matrix[i][j];
  }
}
cout<<"Original Matrix:\n";
for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
   cout<<matrix[i][j]<<" ";
  }
 cout<<"\n";
}
cout<<"\n\nTranspose of Matrix:\n";

for(i=0;i<4;i++)
{
  for(j=0;j<3;j++)
  {
   cout<<transpose_matrix[i][j]<<" ";
  }
cout<<"\n";
}

getch();
}

Tuesday, October 18, 2011

Tutorial on Prefix and Postfix in C programming


The prefix and postfix notations in C++ are really simple for an expert but extremely difficult for novice to understand. In this tutorial, you can easily understand the working of increment and decrement operators in prefix and postfix notation.

Consider the following codes
Code 1
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int b,i=10;
b=i++ + ++i;
cout<<b;
getch();
}

OUTPUT will be 22.

Code 2
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i=10;
i=i++ + ++i;
cout<<i;
getch();
}

OUTPUT will be 23.

Wonder how? Do not wonder. I will explain how it works.

Explanation: Prefix notation is always given first priority over postfix notation to execute. Just see the priority setting for each operation and understand how it works:

Code 1
b=3(i++)4 +2 (++i)1;

See the priority orders as 1, 2, 3 and 4. First prefix i increases and becomes 11. Secondly, + operator adds 11+11 and thirdly = operator assigns 22 to b and lastly postfix i increases to 12. So finally b=22 and i=12.

Code 2
i=3(i++)4 +2 (++i)1;

See the priority orders as 1, 2, 3 and 4. First prefix i increases and becomes 11. Secondly, + operator adds 11+11 and thirdly = operator assigns 22 to i and lastly postfix i increases to 23. So finally i=23.

I hope you understood the working of prefix and postfix in the above examples. Share it if you liked this tutorial.

Monday, October 17, 2011

C++ program to check a palindrome string

//C++ program to check a palindrome string

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int i,j,flag=0;
char string[20];
cout<<"Enter A String\n";
cin>>string;
for(i=0;string[i]!='\0';i++);
for(j=0,--i;i>=0;--i,++j)
{
if(string[i]!=string[j])
{
flag=1;
break;
}
}
if(flag)
cout<<"Not a palindrome string";
else
cout<<"Palindrome String"; 
getch();
}


OUTPUT:



C++ program to calculate length of a string


//C++ program to calculate the length of the string
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int i;
char string[20];
cout<<"Enter A String\n";
gets(string);
for(i=0;string[i]!='\0';i++);
cout<<"The length of the string is"<<i;
getch();
}

Output:


C++ program to print reverse of a string


//C++ program to print reverse of a string
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int i;
char string[20];
cout<<"Enter A String\n";
gets(string);
for(i=0;string[i]!='\0';i++);
for(i=i-1;i>=0;i--)
{
cout<<string[i];
}
getch();
}


Output:


Sunday, October 16, 2011

C program to print pyramid of asterisks

//C++ program to print pyramid of asterisks
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k,l,sp1=4,sp2=-1;
for(i=1;i<=5;i++,sp1--,sp2=sp2+2)
{
for(j=1;j<=sp1;j++)
{
cout<<" ";
}
if(i==1)
{
cout<<"*";
}
if(i==2||i==3||i==4)
{
cout<<"*";
for(k=1;k<=sp2;k++)
{
cout<<" ";
}
cout<<"*";
}
if(i==5)
{
for(l=1;l<=9;l++)
{
cout<<"*";
}
}
 cout<<"\n";
}
getch();
}


The output:

C++ program to print pattern of numbers with each line reversing the previous line

//C++ program to print pattern of numbers with each line reversing the previous line
#include<iostream.h>
#include<conio.h>
void main()
{
int i,k,t,a=1,s=0;
clrscr();
for(i=6;i>=1; i--)
{
  if(i%2==0)
  {
    for(k=1;k<=i;k++)
{
cout<<a<<"   ";
++a;
}
   cout<<"\n";
   t=a;
   }
 if(i%2!=0)
 {
  for(s=t+i-1;s>=t;s--,a++)
  {
  cout<<s<<"   ";
  }
 cout<<"\n";
 }
     
}
getch();
}

The output will be as following:

Sunday, September 18, 2011

Cloud computing-how it works & providers


If you are looking for the information about cloud computing, how cloud computing works, what is cloud computing or cloud computing companies or providers, you are at right place here as you will find a thorough knowledge about cloud computing in this post.  
how cloud computing works

What is cloud computing or How Cloud Computing Works?

Suppose if you're an IT manager in a large company. Your duty is to make sure that all of your employees have the suitable hardware and software they need to complete their tasks. If you buy computers for each employee, it would be difficult as you have to purchase software license also. The situation gets worse if your company has planned a massive hiring. You will lose your sleep.

To overcome this situation, there is a solution called “Cloud Computing”. If you implement cloud computing in your organization, there will be only one application installed on the systems. Each employee need to use the application to log on to a web based service that hosts al the programs your employee need. Each employee will then use only his or her specific application and work. You will have to take services of cloud computing providers or cloud computing companies. The remote machines owned by cloud computing providers would run everything from spreadsheets, word processing, emails to complex data analysis software. 

So we can define cloud computing as

Cloud computing means “To use multiple servers via a digital network, as if they are a single computer. Quite often, the services provided are thought of a part of cloud computing”

In a cloud computing scenario, there is a major workload transfer. Local systems do not have to do all the heavy lifting when it comes to running applications. The interconnected computers that make up the cloud handle them instead. Software and hardware demands on the clients’ or users’ side decrease. The only thing that a clients’ computer should be able to run is the cloud computing system's interface software, which will be as simple as a Web browser. The rest of the things are taken care by cloud's network

If you think that you have not used cloud computing yet, think again as we all use cloud computing everyday. Here’s the example:

If you have an e-mail account with a Web-based e-mail service like Gmail, Hotmail, Yahoo! Mail, then you have used cloud computing. Instead of running an e-mail program like Microsoft Outlook or Outlook Express on your computer, you simply logon to e-mail servers remotely. The data, software and storage for your email account is not kept on your computer rather it resides on the email service provider’s computer cloud.

Normally a web server runs as a single computer or a group of privately owned computers without a cloud. The computers are capable enough to serve a given amount of requests per minute. The computers can do so with a certain amount of latency per request. If a website or web application suddenly becomes popular, and the amount of requests become large than the web server can handle, the response time of the requested pages will be increased due to overloading. While in case of in times of low load much of the capacity will go unused. In these cases cloud computing is the best solution to save infrastructure, cost and time.

If a website, web application or service is hosted in a cloud, additional processing and compute power is available from the cloud provider. The website would share those servers with probably thousands of other websites of varying size and memory. In case if the website suddenly becomes popular, the cloud can automatically direct more individual computers to work to serve pages for the site, and more money is paid for the extra usage. If it becomes unpopular, however, the amount of money due will be less. Cloud computing is popular for its pay-as-you-go pricing model.

List of Cloud Computing Companies or cloud computing providers
Cloud computing providers

37Signals
Adaptive Computing
Amazon
Appirio
Appistry
Apptix
AppZero
Arjuna
Astadia
Basic Gov
Bluewolf
Caspio
Citrix
Cloud.com
Cloudant
Cloudera
CloudShare
CloudSwitch
Clustercorp
CohesiveFT
Constant Contact
Cordys
Crosscheck Networks
Datapipe
Egnyte
Engine Yard
Enomaly
enStratus
Equinix
Eucalyptus
Flexiant
FreshBooks
GigaSpaces
Gladinet
GoGrid
GoodData
Google Apps
GreenQloud
GridCentric
Hosting.com
iCloud
Imonggo
Intacct
Intalio
Intuit
Jive Software
Joyent
JumpBox
Kaavo
LayeredTech
Model Metrics
Nasuni
Navajo Systems
Navisite
NetSuite
Nimbula
Nimbus
Nimsoft
Nirvanix
Nubifer
Okta
OpenNebula
PanTerra Networks
Parallels
Practice Fusion
Rackspace
Red Hat
Relational Networks
ReliaCloud
Rightscale
rPath
Salesforce.com
Savvis
SoftLayer
SuccessFactors
Sungard
Symplified
Terremark Worldwide
Tropo
Twilio
Vertica
Virtual Ark
VMWare
Voxeo
Whamcloud
Workbooks
Workday
Zoho
Zuora

Learn What is cloud computing in this video


If you want to know more about cloud computing at Wikipedia go to Cloud computing @ Wiki

I hope you enjoyed this post about cloud computing. Now spread this knowledge to your friends and family. Share this post!!! 

Tuesday, September 6, 2011

What is High Level Language

If you are wondering what is High Level Language and want to know the definition of HLL. Just see the video


I hope you learned from this tutorial. Now spread this knowledge

Saturday, September 3, 2011

online information technology quiz-questions and answers

Are you looking for online information technology quiz? If yes, go ahead and find an interesting online IT Quiz. Answer the questions  and know where you stand. Check your score at the end of  the quiz. Do not cheat. Be honest.  So enjoy the Quiz




Now when you have taken the quiz, you have known yourself whether you are an IT geek or not. Congratulations to you if you have scored more than 90%.

Friday, August 19, 2011

how to convert decimal to binary and binary to decimal


HOW TO CONVERT DECIMAL TO BINARY AND BINARY TO DECIMAL

For converting a number from decimal to binary we use repeated division by 2 method. We continue the repeated division by 2 till we get the number less than 2. For example:

Repeated division method:
Divide the decimal number by 2 and store remainder at one place. Continue this process till the decimal number is less than 2. Finally write the remainders in reverse order:

You will understand this concept by this example:
 If we want to convert decimal number 65 to binary, we can do this as following:

Divisor 2
Decimal Number and quotients
Remainder
2
65
2
32
1
2
16
0
2
8
0
2
4
0
2
2
0
2
1
0

0
1
   
Now writing the remainders in reverse order we get 1000001
So Decimal number 65 is 1000001 in binary
One more example:
Convert 45 from decimal to binary
 
Divisor 2
Decimal Number and quotients
Remainder
2
45

2
22
1
2
11
0
2
5
1
2
2
1
2
1
0
2
0
1

Writing the remainders in reverse order we get 101101 which is binary equivalent of 45.

Now if we want to convert vice versa i.e. from binary to decimal, we can use the following method:

Take each digit of binary number from right to left and multiply the digit with 2n in increasing order. Here n starts with 0 and increases by 1. Finally add the individual terms and get the decimal number. You will understand this concept by the following example:


Converting 101101 to decimal

1x25+0x24+1x23+1x22+0x21+1x20

=32+0+8+4+0+1
=45
So the decimal equivalent of 101101 is 45

I hope you have understood the process of converting decimal to binary and vice versa. Your comments are welcome

Thursday, August 18, 2011

Quick sort program in C++

//Quick sort program in C++
#include<conio.h>

#include<iostream.h>
#include<process.h>


void quickSort(int numbers[], int array_size);
void q_sort(int numbers[], int left, int right);


int numbers[5];


int main()
{
   clrscr();
   int i,n;
   cout<<"How many numbers you want to sort: ";
   cin>>n;
   cout<<"Enter "<<n<<" numbers.\n";
   for (i = 0; i<n; i++)
      cin>>numbers[i];
//perform quick sort on array
   q_sort(numbers,0,n-1);


   cout<<"Numbers are sorted\n";
   for (i = 0; i<n; i++)
      cout<<numbers[i]<<"   ";
   getch();
   return(0);
}


// Function to sort
void q_sort(int numbers[], int left, int right)
{
   int pivot, l_hold, r_hold;
   l_hold = left;
   r_hold = right;
   pivot = numbers[left];
   while (left < right)
   {
      while ((numbers[right] >= pivot) && (left < right))
      right--;
      if (left != right)
      {
numbers[left] = numbers[right];
left++;
      }
      while ((numbers[left] <= pivot) && (left < right))
left++;
      if (left != right)
      {
 numbers[right] = numbers[left];
 right--;
      }
   }
   numbers[left] = pivot;
   pivot = left;
   left = l_hold;
   right = r_hold;
   if (left < pivot)
      q_sort(numbers, left, pivot-1);
   if (right > pivot)
      q_sort(numbers, pivot+1, right);
}

C++ program to convert decimal to binary


//program to find binary equivalent of a decimal no.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int arr[10];
int ctr=0;
long int n,quo=0,rem=0;
cout<<"Enter A No. "<<endl;
cin>>n;
for(quo=n;quo!=0;ctr++)
{
rem=quo%2;
arr[ctr]=rem;
quo=quo/2;
}
cout<<"Binary Equivalent Of "<<n<<" is-----> ";
for(ctr=ctr-1;ctr>=0;ctr--)
{
cout<<arr[ctr];
}
getch();
}//end main

C++ program to convert binary to decimal

C++ program to convert binary to decimal

//program to convert a binary no. into decimal no.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
long int n,x;
cout<<"Please enter a binary no. "<<endl;
cin>>n;
x=n;
int rem=0,sum=0;
for(int ctr=0;n>0;ctr++)
{ rem=n%10;
  rem=rem*(pow(2,ctr));
  sum=sum+rem;
  n=n/10;
}
cout<<"Decimal Equivalent of "<<x<<" is "<<sum<<endl;
getch();
}//end main

Wednesday, August 17, 2011

C++ program to convert numbers to words

If you are looking for a C++ program to convert numbers to words, you can find a good C++ program here which can convert numbers to words up to 5 digits.

here is the program:

#include<iostream.h>
#include<conio.h>
void single(int);
void ten2ninety(int);
void elev2nine(int);
void dig2word(int);
void main()
{
clrscr();
int a;
cout<<"\n Enter a number\n";
cin>>a;
dig2word(a);
getch();
}
void dig2word(int y)
{
int s=y,ctr=0,ldig,sdig,l2dig,l3dig,l3rddig;
while(y>0)
{
y=y/10;
++ctr;
}
if(ctr==1)
{
single(s);
return;
}
else if(ctr==2)
{
ldig=s%10;
s=s/10;
sdig=s%10;
 if(ldig==0)
 {
   ten2ninety(sdig);
   return;
 }
 if(sdig==1)
 {
 elev2nine(ldig);
 return;
 }
ten2ninety(sdig);
single(ldig);
return;
}
       else if(ctr==3)
       {
l2dig=s%100;
s=s/100;
sdig=s%10;
if(l2dig==0)
{
single(sdig);
cout<<" Hundred";
return;
}
else
{
single(sdig);
cout<<" Hundred";
dig2word(l2dig);
return;
}
       }
       else if(ctr==4)
       {
l3dig=s%1000;
s=s/1000;
sdig=s%10;
if(l3dig==0)
{
single(sdig);
cout<<" Thousand";
return;
}
else
{
single(sdig);
cout<<" Thousand";
dig2word(l3dig);
return;
}
       }
      else if(ctr==5)
       {
l2dig=s%100;
l3dig=s%1000;
s=s/100;
l3rddig=s%10;
s=s/10;
if(l2dig==0&&l3rddig==0)
{
dig2word(s);
cout<<"Thousand";
return;
}
dig2word(s);
cout<<"Thousand";
dig2word(l3dig);
return;
       }
}
void single(int x)
{
 switch(x)
 {
  case 0:cout<<" Zero ";break;
  case 1:cout<<" One ";break;
  case 2:cout<<" Two ";break;
  case 3:cout<<" Three ";break;
  case 4:cout<<" Four ";break;
  case 5:cout<<" Five ";break;
  case 6:cout<<" Six ";break;
  case 7:cout<<" Seven ";break;
  case 8:cout<<" Eight ";break;
  case 9:cout<<" Nine ";break;
 }
}
void elev2nine(int x)
{
 switch(x)
 {
  case 1:cout<<" Eleven ";break;
  case 2:cout<<" Tweleve ";break;
  case 3:cout<<" Thirteen ";break;
  case 4:cout<<" Fourteen ";break;
  case 5:cout<<" Fifteen ";break;
  case 6:cout<<" Sixteen ";break;
  case 7:cout<<" Seventeen ";break;
  case 8:cout<<" Eighteen ";break;
  case 9:cout<<" Nineteen ";break;
 }
}
void ten2ninety(int x)
{
 switch(x)
 {
  case 1:cout<<" Ten ";break;
  case 2:cout<<" Twenty ";break;
  case 3:cout<<" Thirty ";break;
  case 4:cout<<" Forty ";break;
  case 5:cout<<" Fifty ";break;
  case 6:cout<<" Sixty ";break;
  case 7:cout<<" Seventy ";break;
  case 8:cout<<" Eighty ";break;
  case 9:cout<<" Ninety ";break;
 }
}
 
The above program works best for integer limit that means up to 32767 but if you want up to 99999. convert all "int" to "long int"

C++ program to print armstrong numbers between 1 to 1000


Are you looking for the armstrong numbers program in C++? if yes, read up on to know and learn the armstrong numbers program in C++.

What is armstrog number?
An armstrong number is that number whose digits when raised to power 3 and added produce the number itself for example:

153 = 13 + 53 + 33

The following program prints armstrong numbers between 1 to 1000.


#include<iostream.h>
#include<conio.h>
void arm(int);

void main()
{
                for(int i=1;i<=1000;++i)
                {
                 arm(i);
                }
}
void arm(int a)
{
int b,rem,sum=0;
b=a;
     while(a>0)
     {
      rem=a%10;
      sum=sum+(rem * rem * rem);
      a=a/10;
     }
if(sum==b)
cout<<"Armstrong Num "<<b<<"\n";
}

C++ program to find lcm and hcf


If you are looking for a C++ program to find lcm and hcf of 2 numbers, you will find the program here. The following program accepts 2 numbers and finds lcm and hcf of those numbers. 


Here is the program:

#include<iostream.h>
#include<conio.h>
int lcm(int,int);
int hcf(int,int);
void main()
{
clrscr();
int a,b,l,h;
cout<<"\n Enter 2 numbers\n";
cin>>a>>b;
l=lcm(a,b);
h=hcf(a,b);
cout<<"LCM:"<<l<<"\t"<<"HCF:"<<h;
getch();
}
int lcm(int x,int y)
{
  int i,big;
   big=(x>y)?x:y;


for(i=big;i<=x*y;++i)
{
if(i%x==0&&i%y==0)
{
return i;
}
}
return 0;
}
int hcf(int x,int y)
{
  int i,small,max=1;
  small=(x<y)?x:y;


for(i=1;i<=small;++i)
{
if(x%i==0&&y%i==0)
{
max=i;
}
}
return max;
}