Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, June 27, 2013

Top 5 Computer Programmers in the World

In programming category we have written about History about programming language and Programming languages you're never heard of it, Now time to share about The best 10 Computer programmers around the world.

Programmers are Computer enthusiasts, who communicate with Computer system by writing codes, And they develop software for Computer. A programmer is also known as Coder, Developer and Software engineer.

If we look at history, Ada lovelace (Ada Augusta) was the first programmer and she was student of Charles Babbage. Ada lovelace wrote code for Charles Babbage's Analytical engine.

In 1973 Dennis Ritchie created  "C" programming language, this is the most widely used programming language.
     "I think everybody in this country should learn how to program a Computer because it teaches you how to think"- Steve Jobs

 Top 5 Computer Programmers in the World

Here is a list of world's best programmers around the world who changed computer era by developing computer software, programs and also operating system.

#1.  Dennis Ritchie


Dennis Ritchie (1941-2011) was an American Computer Programmer. Sir. Ritchie developed "C" programming language and co-developer of Unix Operating system. Dennis Ritchie worked for Alcatel-Lucent and for Bell labs.

Dennis Ritchie changed digital era by creating "C" programming language. Lisp, Visual Basic, Pascal, COBOL, Turbo pascal 7.0, PL/1, ADA, these are the programming languages are written in C programming language.  "C" is a best programming language for newbie programmers, Who are interested in learning codes.

Dennis Ritchie and his colleague Ken Thompson received the Turing award for implementing and developing UNIX operating system in the year 1983. 

#2.  Mark Zuckerberg

Mark_zuckerberg

Mark Zuckerberg created Facebook.com when he was 20 years old, Mark and his Harward university friends helped to build Facebook. When Facebook started it was only available for Hardward students. Facebook website is mainly written in C++ and PHP programming language.

Mark is very passionate about programming and codes, In his early age he created a messenger called "Zucknet" that allowed to chat with all computers. In 2003 Mark createdFacemash, the website is all about comparing two Harward university students side by side "Hot or Not" contest.
Some developers re-created Facemash (check here)

In last year Mark Zuckerberg earned more than $2 billion worth stock. And worth $15B according to report of usnews. 


#3.  Steve Wozniak  

Steve_wozniak
              The Brain behind Apple Inc. -Steve Wozniak is an Computer scientist and Programmer 

Steve Woz is well known for developing Apple-1 and Apple-2 :

In early 1976 Woz and Jobs developed a Hardware ,Circuit Board design and Operating system for
Apple- 1 . Apple 1 priced around $666, And sold 50 system boards to Paul Terrell (Computer shop owner) . After Apple-1, Woz developed first Color graphics personal computer with Integer BASIC programming language and they named it as a Apple-2.

For sometime  Steve Wozniak was teaching elementary school students about computer. In2006 Steve Woz published his autobiography iWoz: From Computer Geek to Cult Icon.Now Steve Woz is working for Fusion-io as a Chief Scientist.

#4.  Bill Gates

Bill+Gates+Programmer

Bill Gates: Founder of world's largest software company Microsoft, And also Co-chairman of Gates Foundation.  Also Bill gates is one of the world's richest man in the world. 

Bill started working with computer when he was 13 years old. When he was 17 Bill Gates formed a company called Traf-o-data. And In the age of 20 Bill Gates founded Microsoft Inc. Bill Gates also created MS-DOS Operating system and Windows OS. Currently Microsoft is one of the valuable company in the world. In 2012 Microsoft earns $73.72 Billion.

     "Measuring programming progress by lines of code is like measuring aircraft building progress by weight" - Bill Gates

#5.  Linus Torvalds

Linus Torvalds is a software engineer, hacker and project coordinator. 

In 1991 Linus Torvalds released Linux 0.11 which is written in C programming language. Linux supports more than 20+ platforms. And Linux is a free and open source operating system, Open source means that you can get the source code of the operating system for free.
  "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program" - Linus Torvalds

The Top 5 Programmers lists ends here according to me but there are thousands of best programmers are there Larry page, Brin sergy, Bjarne Stroustrup.

Thursday, September 20, 2012

How to swap two numbers using bitwise operators? Program:

#include <stdio.h>
int main() {
int i = 65;
int k = 120;
printf("\n value of i=%d k=%d before swapping", i, k);
i = i ^ k;
k = i ^ k;
i = i ^ k;
printf("\n value of i=%d k=%d after swapping", i, k);
return 0;
}

******c program remove spaces, blanks from a string*******

C code to remove spaces or excess blanks from a string, For example consider the string

"c programming"
There are two spaces in this string, so our program will print a string
"c programming". It will remove spaces when they occur more than one time consecutively in string anywhere.

C programming code
#include <stdio.h>

int main()
{
char text[100], blank[100];
int c = 0, d = 0;

printf("Enter some text\n");
gets(text);

while (text[c] != '\0')
{
if (!(text[c] == ' ' && text[c+1] == ' ')) {
blank[d] = text[c];
d++;
}
c++;
}

blank[d] = '\0';

printf("Text after removing blanks\n%s\n", blank);

return 0;
}

Matrix multiplication in c

Matrix multiplication in c language: c program to multiply matrices (two dimensional array), this program multiplies two matrices which will be entered by the user. Firstly user will enter the order of a matrix. If the entered orders of two matrix is such that they can't be multiplied then an error message is displayed on the screen. You have already studied the logic t
o multiply them in Mathematics. Matrices are frequently used while doing programming and are used to represent graph data structure, in solving system of linear equations and many more.

Matrix multiplication in c language
#include <stdio.h>

int main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];

printf("Enter the number of rows and columns of first matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of first matrix\n");

for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
scanf("%d", &first[c][d]);

printf("Enter the number of rows and columns of second matrix\n");
scanf("%d%d", &p, &q);

if ( n != p )
printf("Matrices with entered orders can't be multiplied with each other.\n");
else
{
printf("Enter the elements of second matrix\n");

for ( c = 0 ; c < p ; c++ )
for ( d = 0 ; d < q ; d++ )
scanf("%d", &second[c][d]);

for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < q ; d++ )
{
for ( k = 0 ; k < p ; k++ )
{
sum = sum + first[c][k]*second[k][d];
}

multiply[c][d] = sum;
sum = 0;
}
}

printf("Product of entered matrices:-\n");

for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < q ; d++ )
printf("%d\t", multiply[c][d]);

printf("\n");
}
}

return 0;
}

******Add 1 to a given number**********

Write a program to add one to a given number. You are not allowed to use operators like ‘+’, ‘-’, ‘*’, ‘/’, ‘++’, ‘–’ …etc.

Examples:
Input: 12
Output: 13

Input: 6
Output: 7

Yes, you guessed it right, we can use bitwise operators to achieve this. Following are different methods to achieve same using bitwise operators.

Method 1
To add 1 to a number x (say 0011000111), we need to flip all the bits after the rightmost 0 bit (we get 0011000000). Finally, flip the rightmost 0 bit also (we get 0011001000) and we are done.

#include<stdio.h>

int addOne(int x)
{
int m = 1;

/* Flip all the set bits until we find a 0 */
while( x & m )
{
x = x^m;
m <<= 1;
}

/* flip the rightmost 0 bit */
x = x^m;
return x;
}

/* Driver program to test above functions*/
int main()
{
printf("%d", addOne(13));
getchar();
return 0;
}

********Multiply a given Integer with 3.5***********

Given a integer x, write a function that multiplies x with 3.5 and returns the integer result. You are not allowed to use %, /, *.

Examples:
Input: 2
Output: 7

Input: 5
Output: 17 (Ignore the digits after decimal point)

Solution:
1. We can get x*3.5 by adding 2*x, x and x/2. To calculate 2*x, left shift x by 1 and to calculate x/2, right shift x by 2.

#include <stdio.h>

int multiplyWith3Point5(int x)
{
return (x<<1) + x + (x>>1);
} 

/* Driver program to test above functions*/
int main()
{
int x = 4; 
printf("%d", multiplyWith3Point5(x));
getchar();
return 0;
}

*************References in C++******************

When a variable is declared as reference, it becomes an alternative name for an existing variable. A variable can be declared as reference by putting ‘&’ in the declaration.

#include<iostream>
using namespace std;

int main()
{
int x = 10;

// ref is a reference to x.
int& ref = x;

// Value of x is now changed to 20
ref = 20;
cout << "x = " << x << endl ;

// Value of x is now changed to 30
x = 30;
cout << "ref = " << ref << endl ;

return 0;
}
Output:

x = 20
ref = 30
Following is one more example that uses references to swap two variables.

#include<iostream>
using namespace std;

void swap (int& first, int& second)
{
int temp = first;
first = second;
second = temp;
}

int main()
{
int a = 2, b = 3;
swap( a, b );
cout << a << " " << b;
return 0;
}
Output:

3 2 

References vs Pointers
Both references and pointers can be used to change local variables of one function inside another function. Both of them can also be used to save copying of big objects when passed as arguments to functions or returned from functions, to get efficiency gain.
Despite above similarities, there are following differences between references and pointers.

References are less powerful than pointers
1) Once a reference is created, it cannot be later made to reference another object; it cannot be reseated. This is often done with pointers.
2) References cannot be NULL. Pointers are often made NULL to indicate that they are not pointing to any valid thing.
3) A reference must be initialized when declared. There is no such restriction with pointers

Due to the above limitations, references in C++ cannot be used for implementing data structures like Linked List, Tree, etc. In Java, references don’t have above restrictions, and can be used to implement all data structures. References being more powerful in Java, is the main reason Java doesn’t need pointers.

References are safer and easier to use:
1) Safer: Since references must be initialized, wild references like wild pointers are unlikely to exist. It is still possible to have references that don’t refer to a valid location (See questions 5 and 6 in the below exercise )
2) Easier to use: References don’t need dereferencing operator to access the value. They can be used like normal variables. ‘&’ operator is needed only at the time of declaration. Also, members of an object reference can be accessed with dot operator (‘.’), unlike pointers where arrow operator (->) is needed to access members.

Together with the above reasons, there are few places like copy constructor argument where pointer cannot be used. Reference must be used pass the argument in copy constructor. Similarly references must be used for overloading some operators like ++.

****Check whether two strings are anagram of each other*****

Write a function to check whether two given strings are anagram of each other or not. An anagram of a string is another string that contains same characters, only the order of characters can be different. For example, “abcd” and “dabc” are anagram of each other.

Method 1 (Use Sorting)
1) Sort both strings
2) Compare the sorted strings

#include <stdio.h>
#include <string.h>

/* Fucntion prototype for srting a given string using quick sort */
void quickSort(char *arr, int si, int ei);

/* function to check whether two strings are anagram of each other */
bool areAnagram(char *str1, char *str2)
{
// Get lenghts of both strings
int n1 = strlen(str1);
int n2 = strlen(str2);

// If lenght of both strings is not same, then they cannot
// be anagram
if (n1 != n2)
return false;

// Sort both strings
quickSort (str1, 0, n1 - 1);
quickSort (str2, 0, n2 - 1);

// Compare sorted strings
for (int i = 0; i < n1; i++)
if (str1[i] != str2[i])
return false;

return true;
}

// Following functions (exchange and partition are needed for quickSort)
void exchange(char *a, char *b)
{
char temp;
temp = *a;
*a = *b;
*b = temp;
}

int partition(char A[], int si, int ei)
{
char x = A[ei];
int i = (si - 1);
int j;

for (j = si; j <= ei - 1; j++)
{
if(A[j] <= x)
{
i++;
exchange(&A[i], &A[j]);
}
}
exchange (&A[i + 1], &A[ei]);
return (i + 1);
}

/* Implementation of Quick Sort
A[] --> Array to be sorted
si --> Starting index
ei --> Ending index
*/
void quickSort(char A[], int si, int ei)
{
int pi; /* Partitioning index */
if(si < ei)
{
pi = partition(A, si, ei);
quickSort(A, si, pi - 1);
quickSort(A, pi + 1, ei);
}
}

/* Driver program to test to pront printDups*/
int main()
{
char str1[] = "test";
char str2[] = "ttew";
if ( areAnagram(str1, str2) )
printf("The two strings are anagram of each other");
else
printf("The two strings are not anagram of each other");

return 0;
}
Output:

The two strings are not anagram of each other
Time Complexity: Time complexity of this method depends upon the sorting technique used. In the above implementation, quickSort is used which may be O(n^2) in worst case. If we use a O(nLogn) sorting algorithm like merge sort, then the complexity becomes O(nLogn)

Sunday, September 2, 2012

Write a program to check whether a given string is a palindrome.

    Palindrome is a string, which when read in both forward and backward way is same.
    Example: radar, madam, pop, lol, etc.,
    Program:
    #include <stdio.h>
    #include <string.h>
    int main() {
     char string1[20];
     int i, length;
     int flag = 0;
     printf("Enter a string: \n");
     scanf("%s", string1);
    
     length = strlen(string1);
     for(i=0;i < length ;i++){
      if(string1[i] != string1[length-i-1]){
       flag = 1;
       break;
      }
     }
    
     if (flag) {
      printf("%s is not a palindrome\n", string1);
     }
     else {
      printf("%s is a palindrome\n", string1);
     }
     return 0;
    }
    Output:
    Enter a string: radar
    “radar” is a palindrome
    Explanation with example:
    To check if a string is a palindrome or not, a string needs to be compared with the reverse of itself.
    
    Consider a palindrome string: "radar",
    ---------------------------
    index: 0 1 2 3 4
    value: r a d a r
    ---------------------------
    To compare it with the reverse of itself, the following logic is used:
    
    0th character in the char array, string1 is same as 4th character in the same string.
    1st character is same as 3rd character.
    2nd character is same as 2nd character.
    . . . .
    ith character is same as 'length-i-1'th character.
    
    If any one of the above condition fails, flag is set to true(1), which implies that the string is not a palindrome.
    By default, the value of flag is false(0). Hence, if all the conditions are satisf