Triangle of Numbers Program in C Programming

In C Programming Language we can make many type of shape using numbers and other characters. Here I will show how we can create triangle with number. Please see the below program. Comment here for any questions.

We can create various triangle pattern using C Program as follow:

 Triangle C Program 1:

Output of Program:

 Triangle C Program 2:

 Output of Program:

 Triangle C Program 3:

 Output of Program:

 Triangle C Program 4:

 Output of Program:

Please comment here if you have any questions

Palindrome Numbers Program in C Language

Check whether a number is Palindrome number or not in C Programming Language: A palindrome number is a number of which reverse is same.

For example, Some palindrome numbers examples are 121, 212, 12321, -454. To check whether a number is palindrome or not first we reverse it and then compare the number obtained with the original, if both are same then number is palindrome otherwise not. C program for palindrome number is given below.

Algorithm Palindrome number

1. Get the number from command prompt.
2. Reverse the number.
3. Compare it with the given number entered from  Command prompt.
4. If both the numbers are same then print the number is palindrome
5. otherswise print number is not palindrome.

Palindrome number program in C Programming

Output of Program:

Comment here is you ave any queries.

Bulk Email Script in PHP and MySQL Database

In this post, I will show you how we can send an email to multiple receivers using simple PHP script. This script also shows how we can send bulk if we have server limitation on number of emails can be sent in period of time.  Many web hosting provider do not support bulk emails so I have set this script to come out of this limitation.

This Bulk Email script can send HTML email. You can also use this script to send promotional and marketing emails.

In this tutorial we will create three files. First file is HTML content of email, second file is the actual code which sends emails to multiple address one at a time and third file is allowing receivers to unsubscribe from email list.

sample.html

sendmail.php

Replace “http://yourdomain.com/path-to-folder/” with your path to unsubscribe.php

You can set the cron job on sendmail.php on particular time frame. For example if you hosting provider support only 100 mail per hour than you can set cron job par hour and update the value here

unsubscribe.php

 

Comment here if you have any queries. 

Find HCF and LCM in C Programming

C program to find HCF (Highest Common Factor) and LCM( Least Common Multiple): Today I will write a program on how to find HCF and LCM of two integers. HCF is also known as Greatest Common Divisor(GCD) or Greatest Common Factor(GCF).

Here there are three methods to find HCF and LCM in C Programming as follow:

  1. Find HCF and LCM using Loop
  2. Find HCF and LCM using Recursion
  3. Find HCF and LCM using Function

Find HCF and LCM in C Programming using Loop

Output of C Program:

 

Find HCF and LCM in C Programming using Recursion

Find HCF and LCM in C Programming using Function

Please comment if this code is useful to you or having any queries.

Factorial Program in C Programming

Factorial program in C Programming Language: C Program code to find and print factorial of a number.

Factorial can be achieved by three methods as follow:

  1. Factorial Program using loop,
  2. Program using a function to find factorial and
  3. Factorial Program using recursion.

Factorial is represented using ‘!’, so five factorial will be written as (5!), n factorial as (n!). Also n! = n*(n-1)*(n-2)*(n-3)…3.2.1 and zero factorial is defined as one i.e. 0! = 1.

Factorial program in C Programming using ‘for’ loop

Here we find factorial using ‘for’ loop.

Output:

 

Factorial program in C Programming using function

Here we find factorial using function.

 

Factorial program in C Programming using recursion

Here we find factorial using Recursion.

Recursion is a technique in which a function calls itself, for example in above code factorial function is calling itself. To solve a problem using recursion you must first express its solution in recursive form.

Please comment if this post is useful to you or have any queries.

Add, Subtract, Multiply and Division in C Programming Language

Write a program in C Programming to perform basic arithmetic operation like addition, subtraction, multiplication and division. C Programming Language comes with arithmetic operators. Operator we will use in the C Program are:

  • ‘+’ Addition
  • ‘-‘ Subtraction
  • ‘*’ Multiplication
  • ‘/’ Division

This operation can be performed on Integer, Float or Double Number. These are Data Types.

Output:

In c language when we divide two integers we get integer result for example 5/2 evaluates to 2. As a general rule integer/integer = integer and float/integer = float or integer/float = float. So we convert denominator to float in our program, you may also write float in numerator. This explicit conversion is known as typecasting.

Check Odd or Even Number using C Programming Language

Today I will show How can we check a number is odd or even in C Programming Language. We also use different method to identify even and odd numbers.

As we all know if we divide any number by 2 and the remainder is 0 (zero), then that number is Even, Otherwise its odd. We will use same logic here in C Programming. In C Programming we can get remainder by % (Modulus) operator.

For example of modulus operator, 3%2 gives 1 as remainder. Even numbers are in form of (2*x) and Odd numbers are in form of ((2*x)+1). Here ‘x’ is integer number.

Program 1: Check whether number is even or odd using modulus operator

We can also check the whether the number is even or odd using bitwise operator & (AND).

For example, Binary of 9 is 1001. When we perform 9 & 1, The result will be 1 and you may observe that the least significant bit of every odd number is 1, so ( odd_number & 1 ) will be always one and also ( even_number & 1 ) is zero.

Program 2: Check whether number is even or odd using Bitwise operator 

 

Program 3: Check whether number is even or odd using Conditional Operator (Without using ‘if’ Conditional Operator)

In C Programming Language when we divide two integers we get an integer result.

For example the result of 7/3 will be 2. We can take advantage of this and can use it to find whether the number is odd or even. Consider an integer ‘n’ we can first divide by 2 and then multiply it by 2 if the result is the original number then the number is even otherwise the number is odd. For example 11/2 = 5, 5*2 = 10 (which is not equal to eleven), now consider 12/2 = 6 and 6 *2 = 12 ( same as original number). These are some logic which may help you in finding if a number is odd or not.

Program 4: Check whether number is even or odd without using Modulus or Bitwise Operator

 

Setting Different Template/Design for Post per Category – WordPress

WordPress is providing various ways to set different template on category page but How about if I want to set different template for each category for Single Post Page.

Today I will show how can we achieve this with simple code in single.php

First We need to create single post template for various categories as follow

Above three files i create because i want to use different single post page template for my music, SMS, and news category respectively. You can create as much file as you can

You can simply create copy of your single.php file and rename it with new template and do the changes that you want for each category single page.

After that open your single.php file remove all code and add following code.

Please comment here if this post is help to you or you have any queries.

 

Find Distance in km and Miles from latitude and longitude value in PHP

I was wondering How can I find distance between two places using latitude and longitude in PHP. Today I will show you How easily we can calculate the distance between to places in Kilometer and Miles. The example here, takes two values for each place ( latitude and longitude ).

Lets create form to accept latitude and longitude value.

 

Function to find the distance is as follow:

This function accept one parameter which is not mandatory. To get the result in mile pass ‘miles’ as parameter. Otherwise it returns result in kilometer.

Comment here if you have any queries.

Live Demo Here

Thanks,

CallServer FormAPI – Teamsite

What is CallServer in FormAPI – Teamsite?

FormAPI is client-side technology. The user scripts that the template designer writes are loaded into the browser and executed by its JavaScript engine. There are many times, however, when code in the user script needs to access resources on a remote server.

Most commonly, the user script needs to run a database query and use the results to set the value of an item. The canonical example is the address entry form that automatically populates the city and state fields after the user has entered the ZIP code. There is no way the user script can include the entire city/state/ZIP database in the code; that information is best obtained from a server.

In Interwoven Teamsite, CallServer is method to make an HTTP request with a set of attributes-value pairs. The request may take the form of either an HTTP POST or an HTTP GET call. The target server (which can be any process that can handle an HTTP request and make a response, such as a servlet or CGI) reads the request and returns JavaScript code embedded in an HTML page. This page is loaded into a hidden frame, distinct from the frame that contains the user script and FormAPI. FormsPublisher provides a special parent.getScriptFrame() function to this hidden frame that returns the user script frame. In this way, the code returned by the server coexists with the user script and has full access to its methods and data.

The callServer() method is asynchronous. A new thread is started with the HTTP request and completes only when it finishes executing the code returned by the server. The user script code that made the request continues executing immediately after the call to callServer(). For this reason, callServer() is usually the last line of code in an event handler; the logic “picks up” in the hidden frame after the post is complete.

Here is an example illustrating a typical city/state/ZIP code form:

 

The fillCityState() handler is a function that queries a remote server for city and state:

 

The result from a call to the server (which will be given the request like http://myserver/
getCityState?zip=94086) returns code similar to this:

 

One of the hazards of making a remote server request is that it may take too long to return. Worse, it may not return at all. To guard against this problem, a user script can use the JavaScript setTimeOut() function to handle a request that does not return within a specified amount of time. Before it calls the server, setTimeOut() is instructed to execute an error handler function. The code that returns from the server cancels the pending error handler call (if it is running, the request succeeded). If the server does not return in time, the error handler is executed.

Adjust the user script fillCityState() function to set up the time out:

 

Create a callServerFailed() function to handle the error case:

Finally, modify the JavaScript returned from the server to cancel the time out:

This does not handle the case where the server is not down, but simply slow. In this case, after one minute the user is prompted that the ZIP code lookup failed, but several moments later may suddenly see the city and state fields automatically change. To guard against this possibility, modify the callServerFailed() function to cancel the server call:

This request cancels the previous request by making a new one to an empty file. This illustrates an important point about the callServer() method: only one call can be active at a time. Subsequent calls to callServer() will cancel any previous calls.

Important Note:

  1. Use only one CallServer method in Form init for setting initial values in form. To set on init Handler see below code: IWEventRegistry.addFormHandler(“onFormInit”, init);
  2. If on any event you want to set data to more than one element, do not use two call server. Use only one CallServer Method to set all the dropdown.
  3. Above shown is the first way to set the data to elements. Another way to set elements is to set data in array variable and print it on the page in script tag. See below code in perl.

Please comment here if you have any queries or suggestion. I will be posting on generalization of CallServer Method for all the template.