Sunday, January 18, 2015

Show Content Dynamically Using Javascript


Hi friends, today i will tell you how to show content dynamically using Javascript.

Here i am creating a drop down that contains 3 options when user click on any option than corresponding content will display to you.

Code :

<!DOCTYPE html>
<html>
<head>
<title>
Drop Down With Javascript
</title>
<style>
h1
{
display:none;
}
</style>
<script>
function liveShow()
{
var value=document.getElementById('city').value;
if(value=="Chennai")
{
document.getElementById("chennai").style.display="block";
document.getElementById("bangalore").style.display="none";
document.getElementById("delhi").style.display="none";
}

Sunday, January 11, 2015

C Program That Count Odd Number In Fibonacci Series

Hello friends today i am sharing a simple program that will count odd numbers with in Fibonacci series.But before that you have know about fibonacci series,so let me explain.

What is Fibonacci Series ?
       The Fibonacci series is a set of numbers that starts with a one or a zero, followed by a one, and proceeds based on the rule that each number (called a Fibonacci number) is equal to the sum of the preceding two numbers.
In mathematical terms,the sequence F(n) of Fibonacci number is defined by following recurrence relation.
F(n)=F(n-1) + F(n-2) 
with 
F(1)=1 ,F(2)=1
Or 
F(0)=0,F(1)=1

For example:-

1,1,2,3,5,8,13,21,34,........
or
0,1,1,2,3,5,8,13,21,34,.........


                         So if you enter 8, then till 8 we have 4 odd numbers(1,1,3,5).Similarly if you enter 34,then till 34 we have 6 odd numbers(1,1,3,5,13,21). 


Now try to understand this code,I am sure you can easily understand this code..:) :)


Code :-


#include<stdio.h>

#include<conio.h>

int main(){

int num,a=0,b=1,c,count=1;

printf("\n\n\n\n WAP to count odd numbers in fibonacci series");

printf("\n Enter the number:");

scanf("%d",&num);

while(1)

{

c=a+b;

Sunday, January 04, 2015

Java Program For Finding Multiplicative Persistence Of A Given Number


Hey friends how are you? Today after a long time i am sharing this post with all of you.I hope you all are good and healthy..:)


Today i am sharing a java program. In this program we have one function MultiplicativePersistence(num) that take one parameter num  which is positive integer and return its multiplicative persistence which is the number of times you must multiply the digits in num until you reach a single digit.

For example:-

If num is 39 then this program should return 3 because 3 * 9 = 27  and 2 * 7 =14 and finally 1 * 4 = 4 and we get 4 that is single digit.So here it is clear that we need 3 steps to get single digit (4)  from given number (39). 


Java Code


import java.util.Scanner;

class Function {

int MultiplicativePersistence(int num) {

        int count = 0, sum = 1, i;
Boolean r = true;
String string=null;
if (num < 10) {
return 0;

} else {

                         //Convert Integer to String by Integer.ToString()
string = Integer.toString(num);
while (r) {

for (i = 0; i < string.length() - 1; i++) {
                                         
                                         //Integer.parseInt() function convert String to Integer
sum = sum * Integer.parseInt(string.substring(i, i + 1));
}
   

Popular Posts