Ads 468x60px

Sunday, 13 January 2013

Single Dimension Array

Suppose you need to take input of 10 integers and you have to add them. Now if you will declare 10 different variables and will take 10 individual inputs then it is very difficult and complex, so here we can use an Array of integer data type. 

What is an Array? 
Array is a collection of homogeneous elements. 

Syntax
data_type array_name[size];
So if we need to store 10 integers in a same variable then we can write
int a[10];
Here, a variable a is declared which can store maximum 10 numbers. 
Array index starts from 0 so we can take input by writing
cin>>a[0]>>a[1]>>a[2]>>a[3]>>.....a[9];
Looks difficult, right?
We can use loop to reduce the complexity, instead of writing the above long statement for taking input we can take input by looping 
for(i=0;i<10;i++)
{
  cin>>a[i];
}
Now looks easy, lets try it in an example. 

Example 
Write a program to store some numbers (How Many? will defined by user) in an array and calculate the sum of odd and even numbers. 
#include<iostream.h>
#include<conio.h>

void main()
{
 clrscr();
 int a[20];
 int esum=0, osum=0, i, c;
 cout<<"Enter the length:\t";
 cin>>c;
 for(i=0;i<c;i++)
 {
  cout<<"Enter value:\t";
  cin>>a[i];
  if(a[i]%2==0)
  {
   esum=esum+a[i];
  }
  else
  {
   osum=osum+a[i];
  }
 }
 cout<<"Even sum = "<<esum<<endl;
 cout<<"Odd sum = "<<osum<<endl;
 getch();
}
Explanation of the program
Variables declared are:
Array of size 20 (int a[20]);
Three integers esum for even numbers, osum for odd numbers, i for loop and c for length which user will define. 
Now firstly we took input from the user and stored that in the variable c.

Now suppose c = 5. 
Now what the for loop will do?
It will checks the expression which will initialize i with zero (i=0), and then it will checks the condition (i<c) which is true (0 is less than 5) so the control will come inside the loop. 
Now it will print the message that enter a value, and will take an input from the user and which will store in the ith position of the array a, so the value of i is zero (i=0), so the value will stored in the first position a[0]. 

Suppose the value entered is 1 i.e. a[0] = 1;
Now the control will come in the if expression and will check that a[0] % 2 is equals to zero or not, which is not true (1%2 is not equals to 0) so the control will left the statements under if and will comes to else part in else part 
osum = osum + a[0] (osum = 0, defined initially and a[0] = 1)
So now, osum will be assigned as 1 (osum + a[0] -> 0 + 1 = 1)

Now the statements under loop is finished so the loop will go to the last expression which is i++, value of i was initially 0 and it will be incremented by 1 so it will became 1 (i++ = 1), now the loop will again checks for the condition (i<c) which is true (1 is less than 5). 

Now the control will come inside the loop and will ask to input the value and store it on the ith position of array a, the value of i is currently 1, so the value will stored on a[1];

Suppose the value entered is 2 i.e. a[1] = 2;
Now the control will check the expression inside if (a[1] % 2 == 0) which is true (2 % 2 == 0), so the control will come inside if and will perform 
esum = esum + a[1] (esum = 0, defined initially and a[0] = 1)
So now, esum will be assigned as 2 (osum + a[0] -> 0 + 2 = 2)

Now the statements under loop is finished so the loop will go to the last expression which is i++, value of i is currently 1 and it will be incremented by 1 so it will became 2 (i++ = 2) and it will again checks the expression (i<5) which is true (2 < 5) and will repeat the same process until the expression will not become false. 
Output of The Program

Saturday, 12 January 2013

Facebook Comments for Blogger

As you know almost every person is having a facebook profile. So if you will remove your default comment box from your blog and add a facebook comment box then it will be better. It will also promote your blog and will give interactivity like facebook wall because the comments will be likable and threaded just like you do in facebook wall. 
Facebook Comment Box
Now if you want to create the same comment box in your blog then you need to follow the steps given below. 

Step 1: You must hide all the previous comments from your blog, for this go to your blog and from the menus of left side select the last menu which is settings and then post and comments. On Comment Location change it to hide and then click save settings. 


Step 2: Now you have to create a facebook app for your comments. Go to the link given below. 
(Skip The Add from the upper right corner)

Step 3: Now if you are logged in to your facebook account you will ask to Register as a Developer or if you are not logged in then you will be ask to log in and then will ask to 
Register as a Developer. Click on Register as a developer, give the details and register while registering it may ask to to identify your phone number you must identify your number. Now once you registered click on Create New App. 

Step 4: Now you'll see the dialogue box of creating app, just put any name for your comment app in my case I am giving Comments. Just put the name and click on Continue. 
You'll now ask for security check enter the captcha and click on Continue. 

Step 5: Now You have your App ID. Put your domain in App Domains and write your Site URL as shown in the image below and click on Save Changes.
Click to View Larger
Step 6: Now Copy your App ID and paste in the below code. 
<meta content='App_ID'   property='fb:app_id'/>

The first phase is over. Now go to your blog and then template and then click on edit HTML, click on the expand widget template. Now you have the HTML coding of your blog, I will recommend you to take a backup so if anything will go wrong you'll be able to restore. 

Step 7: Find this line <head> and just below it, post the code you created in Step 6

Step 8: Now you have to add the Facebook Comment box to your template. Find one of these lines in your template. 

<div class='post-footer-line post-footer-line-3'>

<p class='post-footer-line post-footer-line-3'>

<data:post.body/>

Step 8: Once you have find any one line from these just copy the following code and paste  below the line you have found. 

Step 9: Save your template and you are done. 

Hurray!! You are now done with making Facebook Comment Box, check your post you'll find the Facebook Comment Box. 

break

The break statement is a jump instruction and can be used inside a switch construct, for loop, while loop and do-while loop. The execution of break statement causes immediate exit from the concern construct and the control is transferred to the statement following the loop. In the loop construct the execution of break statement terminates loop and further execution of the program is reserved with the statement following the body of the loop.

Syntax
break;

Example
#include<iostream.h>
#include<conio.h>

void main()
{
  int i;
  while(1)
  {
    cout<<"Enter 3 to break";
    cin>>i;
    if(i==3)
    {
      cout<<"got 3";
      break;
    }
  }
  getch();
}

Explanation of the program
The control comes inside the loop because in c++ any non zero value is considered as true so the while loop is creating an infinite loop because the expression will always remain true and from the statements within the loop it will always ask to input a value but when we will enter 3 the condition under if will be true and the control will go inside the if block and will print the message got 3 and will break the loop. 

Tribute to Sonu Nigam

As we all know today's best singer is Sonu Nigam. He sung almost every type of songs and in singing no one can beat him he is a legend. Download 30 Best every songs by  Sonu Nigam

Best of Sonu Nigam (Click on The Song to Download)

1. Ada (Garam Masala)

2. Aisa Pehli Baar Hua Hai (Har Dil Jo Pyar Karega)

3. Allah Maaf Kare (Desi Boyz)

4. Apna Mujhe Tu Laga (1920 Evil Returns)

5. Beqarar Main (Had Kar Di Aapne)

6. Chori Chori (Lucky)

7. Do Nishaniyaan (Jhootha Hi Sahi)

8. Ek Pal Ke Liye (Ankahee)

9. Falak Dekhoon (Garam Masala)

10. Gum Shuda (Chalte Chalte)

11. Gumsum Hai Dil Mera (Kya Love Story Hai)

12. Gustaakh Dil (Dil Maange More)

13. Halka Halka Sa Ye (Chocolate)

14. Jane Dil Mein kab Se (Mujhse Dosti Karoge)

15. Jagte Raho (Just Married) 

16. Khamoshiyan Gungunane (One 2 Ka 4)

17. Bolo To (Shabd)

18. Khoya Khoya (Shabd)

19. Lagne Lage Ho (Kuchh Meetha Ho Jaye)

20. Main Agar Kahoon (Om Shanti Om)

21. Meri Mehbooba (Jodi No. 1)

22. Osaka Muraiya (One 2 Ka 4)

23. Rehna Hai Tere Dil Mein (RHTDM)

24. Saamne Aati Ho Tum (Dus)

25. Saathiya (Saathiya)

26. Satrangi (Dil Se)

27. Sun Zara (Lucky)

28. Tanhai (Dil Chahta Hai) 

29. Yeh Dil (Pardes)

30. Yeh Nigaahein (Khoya Khoya Chand)

AVG Internet Security Full Paid Version for Free

Are you spending your money on buying Anti Virus, that is good but don't you think that you are wasting your money when you can get it for free. Here I am talking about a very popular Anti Virus Software AVG Internet Security which is of about 1299 Rupees per year but if you are reading this post you can get it for free. Yes Absolutely Free. 

For getting this for free all you need to do is just download the software package from the link given below. 


Now if you have downloaded and installed it then you are thinking that it is a trial version and will be only active for a month or 30 days, but not to worry more, download your serial key from the link given below. 


All you need to do this is just register your AVG Internet Security with the key and you will not ask to buy it. I am using it since last 2 years and it is awesome, since it is protecting my pc from last 2 years for free then it will protect your pc also. 
Leave Your Comments for the password. 

Atif Aslam Sur Kshetra Performances Download

The audio version of the performances by Atif Aslam in Sur Kshetra. Atif sung many songs in Sur Kshetra live. Sur Kshetra was a singing reality so between India and Pakistan. Atif was leading Pakistan as a Captain and for India Himesh Reshamiya was the Captain. Atif's won the competition with his Nabeel Shaukat Ali, during the show Atif performed many songs, here you can download all the songs sung by him at Sur Kshetra.

Atif Aslam Sur Kshetra Mp3s (Click on the song to download)

1. Ankhiyan Nu Rehn De by Atif Aslam

2. Pehli Nazar Mein and Sajna Tere Bina by Atif Aslam

3. Sun Charkhe Di by Atif Aslam

4. Mayee Nee by Atif Aslam

5. Dilbar Mere and Chura Liya by Atif Aslam and Asha Bhosle

6. Hona Tha Pyar by Atif Aslam and Hadiqa Kiani

7. Pehli Nazar Mein by Atif Aslam

8. Kuch Is Tarah by Atif Aslam

will be updated soon with all songs.