Friday, 5 May 2017

Program to count the number of digits of an integer in c programming

C program to count number of digits in an integer is an important question that often asked to check that whether our knowledge is good or not in c++

so, here we are sharing some codes for counting the numbers of digits in an integer. using these codes you can count the number of digits in an integer in different ways.

simple c program to count the number of digits of an integer using while loop

#include <stdio.h>
int main()
{
     long int a;
    int b = 0;

    printf("Enter an integer: ");
    scanf("%lld", &a);

    while(a != 0)
    {
        // a = a/10
        a /= 10;
        ++b;
    }

    printf("Number of digits: %d", b);
}

Program to count the number of digits of an integer in c programming


Program to count the number of digits of an integer in c programming


Another program to check this problem(Program to count the number of digits of an integer in c programming)


C Program to Count Number of Digits in an Integer using for loop


#include<stdio.h>
int main(){
  long long int a,b=0;

  printf("Enter a number: ");
  scanf("%lld",&a);

  for(;a!=0;a=a/10)
      b++;

  printf("Total digits is:  %d",b);

  return 0;
}

Program to count the number of digits of an integer in c programming
Program to count the number of digits of an integer in c programming

Program to count the number of digits of an integer in c programming

If you like the program "Program to count the number of digits of an integer in c programming " do share with your friends and leave a comment.

Friday, 7 April 2017

Understanding structure In c programming

Understanding structure In C programming: - Which workman is adequate who knows how to repair just a single kind of vehicle? None. The Same thing is valid about C dialect. It wouldn't have been so famous had it been ready to deal with just all ints, or all boys or all scorches at once. In certainty when we handle genuine information, we don't ordinarily manage little particles of data without anyone else—things like whole numbers, characters and such. Rather we manage elements that are accumulations of things, everything having its own traits, similarly as the substance we call a "book" is a gathering of things, for example, title, creator, call number, distributor, the number of pages, date of production, and so on. As should be obvious this information is divergent, for case creator is a string, while the number of pages is a whole number. For managing such accumulations, C gives an information sort called 'structure'. A structure assembles, distinctive particles of data that involve a given element. What's more, a structure is the point of this section.

What is structure and why we use it?

What is structure?

A structure is a client characterized information sort in C which permits you to join diverse information sorts to store a specific kind of record. Structure builds a perplexing information sort in the more significant way. It is fairly like an Array. The main contrast is that exhibit is utilized to store the accumulation of comparative datatypes while structure can store gathering of an information. 

The structure is utilized to speak to a record. Assume you need to store the record of Student which comprises of understudy name, address, move number and age. You can characterize a structure to hold this data.


Why we use it?

We have seen before how ordinary variables can hold one bit of data and how arrays can hold various bits of data of similar information sort. These two data type types handle an incredible assortment of circumstances. Be that as it may, frequently we manage elements that are gathering of divergent data types.
For instance, assume you need to store information about a book. You might need to store its name (a string), its value (a float) and a number of pages in it (an int). On the off chance that information about say 3 such books is to be put away, then we can take after two methodologies:

1 Develop individual arrays, one for putting away names, another for putting away costs and still another for putting away various pages. 

2 Utilize a structure variable. Give us a chance to analyze these two methodologies one by one. For programming, accommodation expects that the names of books would be single character long. Give us a chance to start with a program that employments arrays.


structure In c programming example

main( )
{
char name[3] ;
float price[3] ;
int pages[3], i ;
printf ( "\nEnter names, prices and no. of pages of 3 books\n" ) ;
for ( i = 0 ; i <= 2 ; i++ )
scanf ( "%c %f %d", &name[i], &price[i], &pages[i] );
printf ( "\nAnd this is what you entered\n" ) ;
for ( i = 0 ; i <= 2 ; i++ )
printf ( "%c %f %d\n", name[i], price[i], pages[i] );
}

And here is the result.

Enter names, prices and no. of pages of 3 books
A 100.00 354
C 256.50 682
F 233.70 512
And this is what you entered
A 100.000000 354
C 256.500000 682
F 233.700000 512

This approach doubtlessly permits you to store names, costs, and a number of pages. Be that as it may, as you more likely than not understood, it is a clumsy approach that clouds the way that you are managing a gathering of qualities identified with a solitary substance—the book.

The program turns out to be harder to deal with as the quantity of thing identifying with the book continues expanding. For instance, we would be required to utilize various exhibits, on the off chance that we additionally choose to store a name of the distributor, date of procurement of book, and so forth. To settle this issue, C gives a unique information sort—the structure. A structure contains various information sorts gathered together. These information sorts might possibly be of a similar sort. The taking after case delineates the utilization of this information sort.

main( )
{
struct book
{
char name ;
float price ;
int pages ;
} ;
struct book b1, b2, b3 ;
printf ( "\nEnter names, prices & no. of pages of 3 books\n" ) ;
scanf ( "%c %f %d", &b1.name, &b1.price, &b1.pages ) ;
scanf ( "%c %f %d", &b2.name, &b2.price, &b2.pages ) ;
scanf ( "%c %f %d", &b3.name, &b3.price, &b3.pages ) ;
printf ( "\nAnd this is what you entered" ) ;
printf ( "\n%c %f %d", b1.name, b1.price, b1.pages ) ;
printf ( "\n%c %f %d", b2.name, b2.price, b2.pages ) ;
printf ( "\n%c %f %d", b3.name, b3.price, b3.pages ) ;
}

And here is the output...

Enter names, prices and no. of pages of 3 books
A 100.00 354
C 256.50 682
F 233.70 512

And this is what you entered
A 100.000000 354
C 256.500000 682
F 233.700000 512

This program shows two central parts of structures: 

(a) declaration of a structure 

(b) getting to of structure components 

Give us now a chance to take a gander at these ideas one by one

Declaring a Structure in c programming

In our example program, the following statement declares the
structure type in c programming:

struct book
{
char name ;
float price ;
int pages ;
} ;

This announcement characterizes another information sort called struct book. Each variable of this information sort will comprise of a character variable called name, a float variable called cost and an integer variable called pages. The general type of a structure affirmation explanation is given beneath:

struct <structure name>
{
structure element 1 ;
structure element 2 ;
structure element 3 ;
......
......
} ;

Once the new structure information sort has been characterized at least one factors can be proclaimed to be of that sort. For instance, the factors b1, b2, b3 can be proclaimed to be the sort struct book, as,

struct book b1, b2, b3 ;

This announcement puts aside space in memory. It makes accessible space to hold every one of the components in the structure—for this situation, 7 bytes—one for a name, four for cost and two for pages. These bytes are dependably in neighboring memory areas.
If we so desire, we can combine the declaration of the structure type and the structure variables in one statement.

For example,
struct book
{
char name ;
float price ;
int pages ;
} ;
struct book b1, b2, b3 ;
is same as...
struct book
{
char name ;
float price ;
int pages ;
} b1, b2, b3 ;
or even...
struct
{
char name ;
float price ;
int pages ;
} b1, b2, b3 ;

Like essential factors and arrays, structure factors can likewise be introduced where they are announced. The organization utilized is very like that used to start arrays.

struct book
{
char name[10] ;
float price ;
int pages ;
} ;
struct book b1 = { "Basic", 130.00, 550 } ;
struct book b2 = { "Physics", 150.80, 800 } ;

Take note of the accompanying focuses while declaring a structure type:

1 The end prop in the structure sort assertion must be taken after by a semicolon. 

2 Understand that a structure sort assertion does not advise the compiler to save any space in memory. All a structure presentation does is, it characterizes the "shape" of the structure. 

3 Generally, structure sort statement shows up at the highest point of the source code document before any factors or capacities are characterized. In extensive projects, they are normally placed in a different header document and the record is incorporated (utilizing the preprocessor mandate #include) in whichever program we need to utilize this structure sort.

Accessing Structure Elements

Having pronounced the structure sort and the structure factors, let we perceive how the components of the structure can be gotten to. In arrays, we can get to individual components of an array utilizing a subscript. Structures utilize an alternate plan. They utilize a speck (.) administrator. So to allude to pages of the structure characterized, in our test program we need to utilize,

b1.pages
Similarly, to refer to price we would use,
b1.price
Note that before the dot there must always be a structure variable
and after the dot, there must always be a structure element.

How Structure Elements are Stored

Whatever be the components of a structure, they have constantly put away in touching memory areas. The accompanying system would represent this:

/* Memory map of structure elements */
main( )
{
struct book
{
char name ;
float price ;
int pages ;
} ;
struct book b1 = { 'B', 130.00, 550 } ;
printf ( "\nAddress of name = %u", &b1.name ) ;
printf ( "\nAddress of price = %u", &b1.price ) ;
printf ( "\nAddress of pages = %u", &b1.pages ) ;
}

Here is the output of the program...
Address of name = 65518
Address of price = 65519
Address of pages = 65523

Array of Structures

Our specimen program indicating utilization of structure is somewhat basic disapproved. Everything it does is, it gets values into different structure components and yield these qualities. In any case, that is all we planned to do anyway... demonstrate how structure sorts are made, how structure factors are pronounced and how singular components of a structure variable are referenced. 

In our example program, to store information of 100 books we would be required to utilize 100 diverse structure factors from b1 to b100, which is unquestionably not extremely helpful. A superior approach would be to utilize a variety of structures. Taking after program demonstrates to utilize a variety of structures

/* Usage of an array of structures */
main( )
{
struct book
{
char name ;
float price ;
int pages ;
} ;
struct book b[100] ;
int i ;
for ( i = 0 ; i <= 99 ; i++ )
{
printf ( "\nEnter name, price and pages " ) ;
scanf ( "%c %f %d", &b[i].name, &b[i].price, &b[i].pages ) ;
}
for ( i = 0 ; i <= 99 ; i++ )
printf ( "\n%c %f %d", b[i].name, b[i].price, b[i].pages ) ;
}
linkfloat( )
{
float a = 0, *b ;
b = &a ; /* cause emulator to be linked */
a = *b ; /* suppress the warning - variable not used */
}

Now few thing about the program

1 See how the variety of structures is proclaimed... 
struct book b[100] ; 
This gives space in memory to 100 structures of the sort struct book.

2 The language structure we use to reference every component of the array b is like the punctuation utilized for arrays of ints and roasts. For illustration, we allude to zeroth book's cost as b[0].price. Likewise, we allude first book's pages as b[1].pages.

It ought to be acknowledged what watchful thought Dennis Ritchie has put into C dialect. He initially characterized cluster as a gathering of comparable components; then understood that disparate information sorts that are frequently found, all things considered, can't be dealt with utilizing clusters, in this manner made another information sort called structure. In any case notwithstanding utilizing structures programming accommodation couldn't be accomplished, in light of the fact that a considerable measure of factors (b1 to b100 for putting away  information around hundred books) should have been taken care of. In this manner he permitted us to make a variety of structures; a variety of comparable information sorts which themselves are an accumulation of disparate information sorts. Caps off to the virtuoso!

In an array of structures, all components of the array are put away in neighboring memory areas. Since every component of this array is a structure, and since all structure components are constantly put away in neighboring areas, you can picture the game plan of an array of structures in memory. In our illustration, b[0]'s name,, cost and pages in memory would be quickly taken after by b[1]'s name,, cost and pages, and so on.

What is the capacity linkfloat( ) doing here? In the event that you don't characterize it you will undoubtedly get the blunder "Coasting Point Designs Not Linked" with dominant part of C Compilers. What makes this mistake happen? While parsing our source record, if the compiler experiences a reference to the address of a float, it sets a banner to have the linker connect in the floating point emulator. A floating point emulator is utilized to control floating point numbers in runtime library functions like scanf( ) and atof( ). There are a few cases in which the reference to the float is somewhat dark and the compiler does not distinguish the requirement for the emulator. The most widely recognized are utilizing scanf( ) to peruse a float in an array of structures as appeared in our program. 

How might we constrain the arrangements to be connected? That is the place the linkfloat( ) work comes in. It powers connecting of the coasting point emulator into an application. There is no need to call this capacity, simply characterize it anyplace in your program.

Uses Of Structure

Where are structures valuable? The prompt application that strikes a chord is Database Management. That is, to keep up information about representatives in an association, books in a library, things in a store, budgetary bookkeeping exchanges in an organization and so on. In any case mind you, utilization of structures extends much past database administration. They can be utilized for an assortment of purposes like:
  • Changing the extent of the cursor 
  • Clearing the substance of the screen 
  • Putting the cursor at a fitting position on screen 
  • Drawing any illustrations shape or graphics shape on the screen 
  • Getting a key from the console 
  • Checking the memory size of the PC 
  • Discovering the rundown of hardware joined to the PC 
  • Designing a floppy 
  • Concealing a record from the registry 
  • Showing the registry of a circle 
  • Sending the yield to printer 
  • Associating with the mouse

Conclusion

  1. A structure is normally utilized when we wish to store disparate information together. 
  2. Structure components can be gotten to through a structure variable utilizing a speck (.) administrator. 
  3. Structure components can be gotten to through a pointer to a structure utilizing the bolt (- >) administrator. 
  4. All components of one structure variable can be allotted to another structure variable utilizing the task (=) administrator. 
  5. It is conceivable to pass a structure variable to a capacity either by esteem or by address. 
  6. It is conceivable to make a variety of structures.

Some example of structure

How to calculate difference between  two time periods


#include <stdio.h>
struct TIME
{
  int seconds;
  int minutes;
  int hours;
};
void differenceBetweenTimePeriod(struct TIME t1, struct TIME t2, struct TIME *diff);

int main()
{
    struct TIME startTime, stopTime, diff;

    printf("Enter start time: \n");
    printf("Enter hours, minutes and seconds respectively: ");
    scanf("%d %d %d", &startTime.hours, &startTime.minutes, &startTime.seconds);

    printf("Enter stop time: \n");
    printf("Enter hours, minutes and seconds respectively: ");
    scanf("%d %d %d", &stopTime.hours, &stopTime.minutes, &stopTime.seconds);

  
    differenceBetweenTimePeriod(startTime, stopTime, &diff);

    printf("\nTIME DIFFERENCE: %d:%d:%d - ", startTime.hours, startTime.minutes, startTime.seconds);
    printf("%d:%d:%d ", stopTime.hours, stopTime.minutes, stopTime.seconds);
    printf("= %d:%d:%d\n", diff.hours, diff.minutes, diff.seconds);

    return 0;
}

void differenceBetweenTimePeriod(struct TIME start, struct TIME stop, struct TIME *diff)
{
    if(stop.seconds > start.seconds){
        --start.minutes;
        start.seconds += 60;
    }

    diff->seconds = start.seconds - stop.seconds;
    if(stop.minutes > start.minutes){
        --start.hours;
        start.minutes += 60;
    }

    diff->minutes = start.minutes - stop.minutes;
    diff->hours = start.hours - stop.hours;
}


Let see another example of structure

#include <stdio.h>  
#include <string.h>  
struct employee    
{   int id;    
    char name[50];    
    float salary;    
}e1,e2;  
int main( )  
{  
   e1.id=101;  
   strcpy(e1.name, "Suraj tiwari"); 
   e1.salary=56000;  

   e2.id=102;  
   strcpy(e2.name, "rahul thakur");  
   e2.salary=126000;  
   
   printf( "employee 1 id : %d\n", e1.id);  
   printf( "employee 1 name : %s\n", e1.name);  
   printf( "employee 1 salary : %f\n", e1.salary);  
  
   printf( "employee 2 id : %d\n", e2.id);  
   printf( "employee 2 name : %s\n", e2.name);  
   printf( "employee 2 salary : %f\n", e2.salary);  
  
   return 0;  

Friday, 24 March 2017

What is a virtual function in derived class in cpp programming

A virtual function is a part function that you hope to be reclassified in derived classes. When you allude to a derived class object utilizing a pointer or a reference to the base class, you can call a virtual function for that protest and execute the derived class' adaptation of the capacity.

A virtual function is a complicated beast and we are not through with it as yet. We know that when we perform inheritance and redefine some of the virtual functions the compiler creates a new VTABLE for the derived class and inserts into it the new function addresses. If in the derived class we do not redefine the virtual functions, then it inserts the base-class function addresses in the derived class's VTABLE. This means there's  always a full set of function address in the VTABLE. Thus a possibility of you calling a function and its address not existing in the VTABLE is ruled out.
Let us now consider a case when we inherit and new virtual functions in the derived class. The following program shows this possibility.

#include <iostream>
using namespace std;

class base
{
public :

virtual void fun1( )
{

cout<<endl<<"in base::fun1";

}
};

class derived : public base
{
public:
void fun1( )
{
cout << endl<< "in derived::fun1";
}
virtual void fun2( )
{
cout << endl<<"in derived::fun2";
}

};

int main( )
{
base*ptr1, *ptr2;
base b;
derived d;
ptr1 = &b;
ptr2 = &d;
ptr1->fun1( );
ptr2->fun1( );
ptr2->fun2( ); //error
return 0;
}

Here the class base contains a single virtual function fun1( ). The derived redefines fun1( ) and adds another virtual function called fun2( ). The VTABLEs created by the compiler for base and derived are shown in the below figure

The compiler would pass the calls  to fun1( ), but it would report an error for the call

ptr2-> fun( ) ;

In this case, the compiler is working only with a pointer to a base class object. The base class doesn't have the fun2( ) function so the compiler cannot allow a call to fun2( ). The compiler doesn't know that you are working with a derived object if it has only a pointer to a base class
object.

The conclusion is that the compiler prevents you from making calls to virtual functions that exist only in derived classes.

Monday, 6 March 2017

Fibonacci-series-In-JavaScript

Fibonacci numbers are the numbers in the accompanying whole number succession, called the Fibonacci series. In this Post, we will try to explain Fibonacci series in the different method. Hope You will Understand this program. any query you can comment below.  save all the files with (.HTML) extension.


 Fibonacci Series (1-10)


<html>
<body>
<script type="text/javascript">
var a=0,b=1,c;
document.write("Fibonacci");
while (b<=10)
{
document.write(c);
document.write("<br/>");
c=a+b;
a=b;
b=c;
}
</script>
</body>
</html>

Fibonacci series (input from user) 

<html>
 <head>
 <title>FibonacciSeries Using JavaScript</title>
 <script>
 function on_btn_gen_click() {
 count = parseInt(document.getElementById("in1").value);
 a = 0, b = 1, sum = 0;
 output = "<b>The first " + count + " elements in the Fibonacci series:</b> ";

 for(i = 0; i < count; i ++) {
 output += a + " ";
 sum = a + b;
 a = b;
 b = sum;
 }

 document.getElementById("p1").innerHTML = output;
 }
 </script>
 </head>
 <body bgcolor="LightGreen">
 <h1>Fibonacci Series</h1>
 <h2>Helps2code</h2>
 Enter the count of terms: <input id="in1" />
 <button id="btnGen" onclick="on_btn_gen_click()">ClickHere</button>
 <p id="p1" />
 </body>
</html>



Wednesday, 1 March 2017

Three-Dimensional Array in c

We wouldn't demonstrate a programming illustration that uses a three-dimensional array. This is on account of, practically speaking, one seldom utilizes this array. In any case, a case of instating a three-dimensional
an array will merge your comprehension of subscripts:

int arr[3][4][2] = {
{
{ 2, 4 },
{ 7, 8 },
{ 3, 4 },
{ 5, 6 }
},
{
{ 7, 6 },
{ 3, 4 },
{ 5, 3 },
{ 2, 3 }
},
{
{ 8, 9 },
{ 7, 2 },
{ 3, 4 },
{ 5, 1 },
}
} ;


A three-dimensional array can be considered as a variety of array 

of arrays. The external array has three components, each of which is a 

two-dimensional array of four one-dimensional arrays, each of 

which contains two whole numbers. As it were, a one-dimensional 

an array of two components is built first. At that point, four such one-dimensional arrays are put one beneath the other to give a two-dimensional array containing four lines. At that point, three such two-dimensional arrays are set one behind the other to yield a three-dimensional array containing three 2-dimensional arrays. In the 

array statement takes note of how the commas have been given. Figure 


8.9 would potentially help you in envisioning the circumstance better.



Three-Dimensional Array in c





Again recollect that the game plan appeared above is as it were 

reasonably genuine. In memory, similar array components are put away 


directly as appeared in Figure 8.10.




Three-Dimensional Array in c




How would you refer to the array element 1 in the above array?
The first subscript should be [2], since the element is in third twodimensional array; the second subscript should be [3] since the
element is in fourth row of the two-dimensional array; and the
third subscript should be [1] since the element is in second position
in the one-dimensional array. We can therefore say that the
element 1 can be referred as arr[2][3][1]. It may be noted here that
the counting of array elements even for a 3-D array begins with
zero. Can we not refer to this element using pointer notation? Of
course, yes. For example, the following two expressions refer to

the same element in the 3-D array:

arr[2][3][1]

*( *( *( arr + 2 ) + 3 ) + 1 )


Summary

1)   An array is like a customary variable aside from that it can 

store various components of comparable sort.

2)   Compiler doesn’t perform bounds checking on an array.

3)   The array variable goes about as a pointer to the zeroth component of 

4)   the exhibit. In a 1-D exhibit, zeroth component is a solitary esteem, 

while, in a 2-D cluster this component is a 1-D exhibit.


5)   On incrementing a pointer it points to the next location of its

type

6)   array components are put away in touching memory areas 

thus they can be gotten to utilizing pointers.

7)   Only limited arithmetic can be done on pointers.

Java Program For Linear Search

Linear Search is a search method, in which the way to be searched is contrasted and every component in the rundown until it is found. This strategy works regardless of the possibility that the rundown is not sorted. It is thought to be slower than double hunt as the measure of the information (list) develops. Java Program For Linear Search


Here is the code for Linear Search in java/Java Program For Linear Search


import java.io.*;
class LinearSearch{
public static void main(String args[])throws IOException{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
int a[]={92, 34, 78, 12, 45, 7, 81, 60, 51, 10};
int key, i;
System.out.print("Enter the integer to search:");
key=Integer.parseInt(br.readLine());
for(i=0;i<a.length;i++){
if(key==a[i])
break;
}
if(i==10)
System.out.println(key+" not found");
else
System.out.println(key+" found at index "+i);
}
}

Another Program For Linear Search/Java Program For Linear Search

import java.io.*;

public class LinearSearch
{
  public static void main(String args[]) throws Exception
  {
    int values[] = {5, 16, 10, 17, 8, 25};
    int key;
    int i;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Array values are:");
    for(int n:values)
    {
      System.out.print(n+"\t");
    }
    System.out.println("\nPlease enter a key (search) value:");
    key = Integer.parseInt(br.readLine());
    for(i=0; i< values.length; i++)
    {
      if(values[i] == key)
      {
        break;
      }
    }
    if(i==values.length)
    {
      System.out.println(key+" not found...!");
    }
    else
    {
      System.out.println(key+" found at position "+(i+1));
    }
  }

}


Java Program to Search an Element in an Array using Linear Search/Java Program For Linear Search


package com.tcc.java.programs;

import java.util.*;

public class ArrayLinearSearch {
    public static void main(String args[]) {
        int count, num, i;
        int[] inputArray = new int[500];
 
        Scanner in = new Scanner(System.in);
 
        System.out.println("Enter number of elements");
        count = in.nextInt();
        System.out.println("Enter " + count + " elements");
        for(i = 0; i < count; i++) {
            inputArray[i] = in.nextInt();
        }

        System.out.println("Enter element to search");
        num = in.nextInt();
        // Compare each element of array with num
        for (i = 0; i < count ; i++) {
            if(num == inputArray[i]){
               System.out.println(num+" is present at index "+i);
               break;
            }
        }
 
        if(i == count)
           System.out.println(num + " not present in input array");
    }
}

If you like this program Java Program For Linear Search do a comment and let us know

Wednesday, 22 February 2017

PYTHON IF...ELIF...ELSE

Q. What is if else?
 The if/else means a statement that executes a block of code if a specified condition is true and if the condition is false, another block of code can be executed.
Example Of IF...ELSE

x = int(raw_input("Please enter an integer: "))
Please enter an integer: 42
 if x < 0:
    x = 0
    print 'Negative changed to zero'
 elif x == 0:
     print 'Zero'
 elif x == 1:
     print 'Single'
 else:

     print 'More'

Python Program To Check If a Number Is Odd or Even(Using IF...ELSE)

Q. What is ELIF?
With elif statement you can check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE.
It is similar to the else, the elif statement is optional. However, unlike else, for which there can be at most one statement, there can be an arbitrary number of elif statements following an if.


You May Like Also :-  Python Program To swap Two Variables

people = 30
cars = 40
trucks = 15


if cars > people:
    print "We should take the cars."
elif cars < people:
    print "We should not take the cars."
else:
    print "We can't decide."

if trucks > cars:
    print "That's too many trucks."
elif trucks < cars:
    print "Maybe we could take the trucks."
else:
    print "We still can't decide."

if people > trucks:
    print "Alright, let's just take the trucks."
else:
    print "Fine, let's stay home then."

Python program to check if a number is positive, negative or zero (Using IF...ELIF...ELSE )

num = float(input("Enter a number: "))
if num > 0:
   print("Positive number")
elif num == 0:
   print("Zero")
else:
   print("Negative number")



Python Program To Check Leap Year(Using Nested IF..ELSE)

 Python program to check if the input year is a leap year or not

year = 2000

# To get year (integer input) from the user
# year = int(input("Enter a year: "))

if (year % 4) == 0:
   if (year % 100) == 0:
       if (year % 400) == 0:
           print("{0} is a leap year".format(year))
       else:
           print("{0} is not a leap year".format(year))
   else:
       print("{0} is a leap year".format(year))
else:
   print("{0} is not a leap year".format(year))


Important JavaScript Interview Questions

 JavaScript Interview Questions 
1. What is JavaScript?
Javascript is client-side as well as server facet scripting language that can be inserted into HTML pages and is understood through internet browsers. javascript is likewise an item orientated programming language

2. Which company developed JavaScript?
Netscape is the software organization who evolved javascript. 

3. What is a prompt box?
a prompt box is a container which lets in the user to go into input by way of supplying a textual content box.  label and container will be supplied to enter the textual content or wide variety.

4. What is ‘this’ keyword in JavaScript?
‘this’ keyword refers to the object from where it became called.

5. What is the difference between ViewState and SessionState?

‘ViewState’ is specific to a page in a session.

‘SessionState’ is specific to user specific data that can be accessed across all pages in the web application.

6. What is = = = operator?
= = = is referred to as-is strict equality operator which returns authentic when the 2 operands are having the identical cost with none kind conversion.

7. Explain how can you submit a form using JavaScript?
to post a form using javascript use file.shape[0].publish();

report.shape[0].post();

8. Explain how to read and write a file using JavaScript?
To put up a shape the use of javascript use document.shape[0].post();

file.shape[0].submit();


there are  approaches to read and write a report the use of javascript

using javascript extensions
using a web page and energetic x gadgets.

9. Name some of the JavaScript features.

Following are the features of JavaScript −

*  javascript is a light-weight, interpreted programming language.
*  javascript is designed for developing community-centric programs
*  javascript is complementary to and integrated with java.
*  javascript is open and go platform.

10. What are the advantages of using JavaScript?

Following are the advantages of using JavaScript −

Much less server interplay − you can validate consumer input earlier than sending the page off to the server. this saves server site visitors, because of this much less load on your server.

Instantaneous remarks to the traffic − they do not ought to watch for a page reload to see in the event that they have forgotten to go into something.

Increased interactivity − you can create interfaces that react whilst the user hovers over them with a mouse or activates them through the keyboard.

Richer interfaces − you can use javascript to include such gadgets as drag-and-drop components and sliders to present a rich interface on your site visitors.

11. Is JavaScript a case-sensitive language?

sure! javascript is a case-sensitive language. which means that language keywords, variables, function names, and any other identifiers should usually be typed with a steady capitalization of letters.

12. How can you create an array in javascript?
you could outline arrays the use of the array literal as follows −

var x = [];
var y = [1, 2, 3, 4, 5];

13. How can you convert the string of any base to an integer in JavaScript?

the parseint() characteristic is used to convert numbers among extraordinary bases. parseint() takes the string to be transformed as its first parameter, and the second one parameter is the base of the given string.

on the way to convert 4f (of base 16) to integer, the code used might be –

parseInt ("4F", 16);

14. What is the function of delete operator?
The functionality of delete operator is used to delete all variables and gadgets in a software however it can not delete variables declared with var key-word.

15. What is The difference between an alert box and a confirmation box ?

an alert box presentations best one button which is the adequate button.


but a confirmation box presentations two buttons particularly ok and cancel.

16. What are the valid scopes of a variable in JavaScript?

the scope of a variable is the region of your program wherein it's far defined. javascript variable can have best  scopes.

Global variables − a global variable has global scope which means it's miles seen everywhere in your javascript code.

local variables − a local variable will be seen only within a characteristic where it's far defined. function parameters are always local to that feature.




Tuesday, 21 February 2017

10 reasons to use MySQL

10 reasons to use MySQL

So here’s the reasons why someone would use MySQL and why we shouldn’t be making funeral plans for it just yet.

1. It’s ubiquitous

Go to any Linux or Windows based web have, and there it is. Download an open source venture and a large portion of time that is what it's associated with. In case you're in a common facilitating condition you can't simply go an introduce something else, yet you can stay with MySQL and download pretty much any open source programming and utilize it. That is favorable position, particularly for new people.

2. It’s easy to find help

If you get stuck on something, there are countless places to find your solution. There are tens of thousands of tutorials, help docs and discussions about it. Chances are the problem you’re having isn’t anything new and someone has already solved it.

3. It’s easy to learn

Basically anybody can take in the rudiments and get up and running rapidly with MySQL. In case you're building something little and straightforward it's simple, and very sympathetic. While this constructs poor programming rehearses it likewise gives individuals preparing wheels until they take in more and choose to get a genuine database.

4. MySQL is considered proven

While it may not be impeccable, it is viewed as a demonstrated innovation in the business. Merchants endeavor to have their applications and apparatuses perfect with MySQL in light of the fact that it's so every now and again utilized effectively. There are a lot of uses that utilization MySQL intelligently to take care of their issues, and they work fine and dandy.

5. Less features mean less maintenance
you don’t want to rent a group of licensed dbas to run a mysql database. an normal programmer can study enough to keep their database servers for most programs. there are numerous features enterprise database providers provide that you can’t find in mysql, but you furthermore mght don’t want. maximum of the time the ones extra functions imply extra points of failure, and greater training needed to keep the server running, that is wasteful in case you aren’t actively using stated capabilities anyway. mysql may be very much “set it and neglect it” in many programs.

6. Total Cost of Ownership (TCO)

what number of startups available need to fork out hundreds of bucks for a microsoft or oracle answer? they’re operating on a shoestring so a loose database solution is a no brainer. mysql may be installed on as many servers as you need and it doesn’t require tons in the way of hardware. and as i cited earlier than the hard work costs for keeping it are a long way lower. even big set up agencies love saving money, and mysql saves money.

If you don’t need the extra features you aren’t going to pay through the nose for it, pure and simple.

7. MySQL is scalable

You and your brother in law decide to start a company in your garage. You choose MySQL based on price and build your application. Fast forward a year from now and things are growing good. You’ve added a couple more servers and things are fine. Another year goes by and you have some breakthrough and your business is 10 times larger overnight. You can use that money to build as much of an infrastructure as you need, and rather quickly. MySQL can handle everything from a megabyte of data to terabytes just fine. With good education about the system you can scale it up.

8. Native support for the new stuff
in case you really need to be hip and cutting facet you wouldn’t don't forget using that stale and uncool mysql proper? properly surely you might considering how properly it interfaces with such things as ruby and python. it’s properly supported out of the field, and ready for the contemporary and finest technologies coming out, in addition to fantastic aid for Hypertext Preprocessor.

9. Great transactional support

whilst mysql might not be the finest for statistics warehousing it’s tough to argue it’s horrific as a transactional database. the net itself is distinctly transactional and mysql meets that need well. it capabilities acid (atomic, steady, remoted, durable) aid, allotted transactions and server enforced referential integrity assessments on transactions.

10. RDBMS support for smaller businesses isn’t bad

for small to medium sized groups the reporting and evaluation capability is pretty enough. it can use a whole lot of improvement but it works great for smaller applications. the same type of businesses that advantage from value financial savings are the same ones that won’t probable need complicated analysis and in depth bi reporting provided in different databases. in case you’re using it to run your organisation blog or a few purchasing carts do you actually need a lot more than mysql offers? possibly no longer.

when you’re equipped to lose the schooling wheels

ok so if you’re a growing enterprise or your weblog receives huge you'll probable need to shake mysql sooner or later. there are many cases in which you don’t need to use it:

if you have large statistics
enterprise intelligence is more critical than value
you have got a competent and especially technical staff
records accuracy is extraordinarily crucial
your infrastructure is dependent on microsoft or java
you're a small enterprise but have someone who can run postgresql (giggle)
i've particular the motives you need to recall mysql on your answer, and why many people use it. if your targets are to drop in an smooth solution and save some cash it’s excellent. however what about the exceptions? i’ll be writing an editorial about that quickly, because there are masses of motives not to apply it as properly.

for my part i pick postgresql over mysql for a drop in substitute on linux based systems. it’s a ways advanced in many ways, and some thing you need to do not forget in case you’re capable of. in my opinion if i were to begin a brand new business or had a linux primarily based surroundings and become in the making plans section i'd choose postgresql from the start. however it’s now not usually the quality option for most people.

end

i'm hoping this helps shed some light on the truth that mysql is ubiquitous and present for a purpose. it’s not the best solution obtainable, but it’s the satisfactory answer for lots people. as i stated individually i decide on postgresql or ms-square a ways above mysql but i apprehend the reasoning behind choosing mysql and i wish you’ll remember that too.

have to you use mysql? the answer relies upon on what you’re using it for, and what your dreams are. it’s no longer as easy as some are trying to make it.

Why Should I Learn Java

Novice Friendliness 

By and large, Java was intended to be moderately fledgling benevolent in that it expect the software engineer is not that brilliant or watchful, so developers will be less inclined to shoot themselves in the foot when coding Java applications.

Generally Simple to Use 
Why Should I Learn Java
Why Should I Learn Java

Java is an abnormal state dialect, which implies Java abstracts away (i.e. handles for you) the vast majority of the mind-boggling points of interest of the machine (PC, for example, memory administration, and so forth. Therefore, you can concentrate on programming as opposed to agonizing over the little subtle elements many consider both dull and troublesome.

Less Rewarding from the Start 

Java is exceptionally unshakable and verbose, which implies you have to compose a great deal of code attempting to persuade the dialect to fabricate some element. Accordingly, you may need to invest a ton of energy coding before you can get a working application. This might be demotivating for coding amateurs.

Versatility 

Less demanding to Maintain 

Java is a statically-written dialect, which implies your code should be checked for mistakes before it can be incorporated with an application. This implies blunders will be simpler to find. Moreover, since statically-wrote dialects are additionally more strict with the meanings of things, you will have less bizarre and sudden mistakes, which implies your codebase will be less demanding to keep up as it develops in size and many-sided quality.

Quick 

As a statically wrote dialect, Java is speedier than powerfully written dialects since things are all the more unmistakably characterized. In this manner, when the application is running, your machine's assets won't be squandered on checking the meaning of something in your code.

Enhanced Performance 

Present day Java projects are currently significantly more performant on account of develop JIT (without a moment to spare) compilers and enhanced JVMs, as execution can be improved continuously to help a Java program run quicker. This is exceptionally useful as your application becomes bigger or necessities to deal with more procedures.

Group 

Group size is vital on the grounds that the bigger a programming dialect group is, the more support you'd probably get. As you venture into the programming scene, you'll soon see how imperative support is, as the engineer group is about giving and accepting assistance. Also, the bigger a group, the more individuals will assemble helpful apparatuses to make improvement in that specific dialect less demanding.

Starting at now, there are more than 600 striking programming dialects around the world. Thus, in view of that specific situation, how about we dive into the subtle elements of the Java people group estimate.

second Largest StackOverflow Community 

StackOverflow is a programming Q&A site you will probably get to be distinctly close with as a coding learner. Java has a tremendous group for both back-end web advancement and Android improvement.

fourth Largest Meetup Community 

At meetups, you can for the most part system and gain from kindred engineers. Meetups frequently offer mentorship to the individuals who need it also. There are more than 1.4k Java Meetup bunches, totaling more than 580k individuals around the world. Regarding programming dialects, Java has the fourth biggest meetup group.

second Most-labeled Language at GitHub

The more valuable ventures there are, the more probable somebody has officially assembled a capacity you require and fabricated it well, which will extraordinarily accelerate your advancement procedure. GitHub has more than 1.5 million Java ventures, more than 1.1k of which have been featured by more than 500 individuals, making it second place regarding valuable undertakings.,

All in all, the Java biological community is very enormous and develop, so there are a lot of good apparatuses and libraries that will extraordinarily facilitate the way toward creating Java applications and learning Java as a rule.

Vocation Opportunities 

Quickfacts 

Pay data from gooroo.io 

Java is the third Most Demanded Skill on Angel list. Numerous tech goliaths, for example, Google or Amazon additionally utilize Java to build up the back end of their sites, and on the grounds that Java has entirely great execution, a considerable measure of new businesses who achieve the scaling point would coordinate their applications with Java to power includes that need great execution.

As indicated by Indeed.com, Java designers are sought after contrasted with different software engineers:

Future 

As indicated by the TIOBE Index, Java is the Most Popular Language in 2015

Java has a somewhat moderate redesign cycle regarding new forms to guarantee in reverse similarity, and ventures are ease back to embrace changes too, so this works out fine for both sides. Prophet claims Java so the dialect is effectively chipped away at to remain significant, and bugs are settled moderately rapidly.

In spite of the fact that Java has been scrutinized ordinarily and numerous dialects have attempted to supplant it as a superior Java, with the arrival of a superior (Java 8) amid March eighteenth, 2014, Java will obviously keep on staying important and will go solid, particularly since it as of now has many develop apparatuses and libraries that won't be anything but difficult to supplant.

Enthusiasm learning Java developed by 22.4% in 2015 

A writing computer programs dialect's capacity to remain pertinent and survive additionally relies on upon whether the dialect is getting fresh recruits, so plainly Java will keep on dominating in the years to come.

You May Also Like :- Java Program To Print Pattern
                                    How To Reverse An Araay In Java