Showing posts with label Basic Programming. Show all posts
Showing posts with label Basic Programming. Show all posts

Friday 12 September 2014

Even or Odd

Checking Number is Even Or Odd Is very Easy Task .

  1. num=int(raw_input())
  2. if num%2==0:
  3.     print 'Even'
  4. else:
  5.     print 'Odd'


But If Someone say I gave you lots of Numbers to check Until I satisfied that your Program is correct .
And number is in range 0 to 10^10000

Sunday 13 July 2014

Floyd's Triangle

Floyd's Triangle :

1
2  3
4  5  6
7  8  9  10
..
and so on ..


Armstrong Number

Armstrong Number : Numbers who's sum of cube of digits of number is equal to same given number. Then number is called Armstrong Number .

Algorithm for Armstrong Number :


Concept of  Armstrong Number is basically Algorithm to find it . Find sum of cube of digit ,way of finding this may differ according to programming language you choose .

I use Python 2.7 So I can directly convert number into string and accessing character by character and hence find sum of cube of digits

Monday 7 July 2014

Palindrome Number

Palindrome number are very common question we face in programming field .

Palindrome number :

Numbers that remain the same when digit is reversed .
Example : 2, 202 , 101 ,191, 99599, 76567 these are palindrome number

Not palindrome : 123, 3452, 6789, 23434 4561, 34546

How check Number Is Palindrome Or Not :

There are many ways to  check number is palindrome :

Thursday 3 July 2014

How to Find prime factor of a number

Find Prime factor of a number is one of most common question  encounter in basic mathematics . But it has very high uses not only in mathematics problems but also in high level algorithmic programming problems. Mostly problems that uses properties of numbers .
If you wan't to become a programmer ,you will face many problems that uses properties of numbers , and we know a good programmer always try to find best way to solve problem otherwise there is always a straight way (Brute force way ) to solve almost any problem .
But we know it will ruin speed of  programming  result  that's why we always try to find fastest and effective way to solve problems .

Algorithm to Find prime factor of a number :

It uses very basic concept of division

Friday 27 June 2014

Karatsuba Multiplication

This is a Non-traditional way of multiplication .But due to its better time efficiency in computer application It can use as better way of multiplication in computer program.

Note : let we have to find X*Y then Karatsuba Multiplication is applicable if and only if both X &Y have same number of digits .
Ex : x=2345  & y =4535 both have 4 digits


Friday 25 April 2014

Hexadecimal encoder & decoder in Python

Best thing , I love about Python is, It has lots of inbuilt Pre-defined functions . which shorten our code by a large extend .


Hexadecimal encoding & decoding is very easy & need only few lines of  in python . 

Here Is Python2.7 code for Hex conversion from string ,and from Hex to string 

Saturday 22 March 2014

TOWER OF HANOI

This is a famous game for programmer .

Object of the game is to move all the disks over to tower C (final destination let say D )   from tower A (source tower let say S ) with the help of tower B (temporary Tower let say T) .

Condition :  But here is the twist,you cannot place a larger disk onto a smaller disk at any time during your moves.

Monday 10 March 2014

AMICABLE PAIRS


Two numbers form Amicable Pairs  if sum of proper divisors of  1st is equal to the 2nd and vice-versa.It is assumed that these two numbers should be distinct,

Example : Let two number 220 And 284 ,
      Sum of proper Divisor of 220 := 1+2+4+5+10+11+20+22+44+55+110 = 284
      Sum of Proper Divisor of 284 :=1+2+$+71+142=210 .
 That's Why 220 & 284 form amicable number pair .

Note : ( 220 , 284 ) smallest Amicable Number Pair . 

C Code to find Amicable Number in GIven Range : 


Saturday 8 March 2014

An illustration of Calling a Function in C

When you call any function : there are two way to pass Value to it .  Today we discuss benefits of these two approaches .

CALL BY Value :   

In This Cause we just pass a copy of actual value and any change to this data in called function NOT change actual Value of The data in Caller function (which passes argument ).
Take an example : Swapping two number   without using third variable .


Wednesday 5 March 2014

Effective Way to test Number is Prime or Not .

Prime number is one of most frequent thing we face in programming  Problems . But you know most time we use algorithm to test number is prime or not is is very slow if number is too big . In other word our algorithm is not efficient .

But little bit change to that algorithm make it more efficient .

Prime number : 

A integer that has no integral factor except 1 and itself . ( 1 is not treated as prime number )

Now normal Way to solve this is make a for loop from 2 to N/2 & check divisibility for each integer .

Take a look of C code :

Tuesday 4 March 2014

Ways to find Factorial of a Number

This is very frequent direct or indirect questions, we found To find out factorial of a number . There are Many ways to find out factorial of a number .

Factorial of a number :

N factorial =  N! = N*(N-1)*(N-2)*(N-3) ...... *3*2*1

It is basically product of all positive number greater than equal to N .
Ex:
       4! = 4*3*2*1 =24
       5!=5*4! =%*4*3*2*1 =120
      7!=7*6*5*4*3*2*1 = 5040

Note : Factorial of  0 = 0! =1

Monday 3 March 2014

How to Lock And Hide folder using Batch Program

In Daily life Many times you Really need some thing to hide and lock in your computer Such That other Can't see it . For this purpose there are Many software available ,Some of them are free some are Paid .

But today I gonna tell you How to Hide And Lock folder in your windows computer without any software . for this purpose we use batch programming .

If you don't know batch programming Nothing to worry .because  even than you can implement it and Use it and if you know Batch programming you can understand it and also you can modify it according to your need .
For Now This is the required Bat program :

Friday 28 February 2014

PHP crash course -4 ( GET POST & REQUEST function )

We Know PHP is server side language i.e. it execute on server . NOW  user have to insert a data and you have to send this data to server where your PHP code complete operation on that data Then send it back to User . The Problem is How to send this data for this purpose PHP have two Inbuilt feature . They are two Predefined function GET & POST .

Now See How they Work .

First of all make a form which take input Like Name & age. Bye user .
A sample Form for GET method :

Thursday 27 February 2014

Test your Programming Skill : P-2

Our today's Programming Problem is quite  easier . It uses your Basic mathematics skill of School level But Really This Problem Test your skills .

You Have to Find Number of Zeros at end of factorial of a number without using real factorisation
  example : let No be 15 then 15 ! (15 factorial ) =1*2*3* ..........*13*14*15
                 and you have to find out number of Zero's at end of 15 ! = 3
                as 15!=1307674368000 .

I Gave you some results  to check your Program output .  So hurry Up .

Sunday 23 February 2014

Basic Calculator using Switch() loop

When Anyone introduce to programming .He wants to make something productive . And calculator is easiest thing which you can make from your very basic programming . And today we gonna Do this ...

We are going to make first Calculator program in C .

It can do following operation addition, subtraction, Division, Multiplication and Power .
these are very basic operation
steps :

Thursday 31 October 2013

Introduction to java

Java is an advanced programming language then c & c++.
It is purely OBJECT ORIENTED PROGRAMMING......




DATATYPES IN JAVA
All datatypes of C++ inherited into java with some distinct features.

The keywords signed and unsigned are not available in Java.

Tuesday 29 October 2013

Sparse Matrix in C

If a matrix contains lots of ZEROS , then to save time & space,we use a special type of matrix ,known as SPARSE MATRIX.....

It stores only the NON-ZERO Elements only....
It can be created by two ways
1)Using array
2)Using Linklist

Simple e.g-


Let's write a c programe to get the sparse matrix of a given matix [In array]

Saturday 26 October 2013

Vectors in C++

                                                                                 
While programming use of arrays is very common and almost everyone even the beginner knows about it. Now we know that array is a contiguous memory location of fixed size . Here the problem begins that we cannot increase the size of an array later during run time thus we need to declare a very large array and a lot of memory is wasted . So here is the solution , Vectors in simple terms are expandable arrays . Not talking much let's get straight to an example .



Introduction to STL and Containers

                                                                           

The Standard Template Library (STL) is a software library for the C++ programming language that influenced many parts of the C++ Standard Library. It provides four components called algorithmscontainersfunctional, and iterators.
The STL provides a ready-made set of common classes for C++, such as containers and associative arrays, that can be used with any built-in type and with any user-defined type that supports some elementary operations (such as copying and assignment). STL algorithms are independent of containers, which significantly reduces the complexity of the library.

Blogger Widgets