Saturday, November 19, 2011

C Program for Check Armstrong Number

It is a sample C program to find accepted number is Armstrong number on not.


Program Source Code
//Write a program to check accepted number is armstrong number or not.
#include"stdio.h"
#include"conio.h"
void main()
{
  int i,no,r,sum=0;
  clrscr();
  printf("*******Armstrong Number******");
  printf("\n Enter a number");
  scanf("%d",&no);
  i=no;
  while(no!=0)
   {
    r=no%10;
    sum=sum+(r*r*r);
    no=no/10;
   }
   if(sum==i)
    printf("Number is a Armstrong number\n");
   else
    printf("Number is not a armstrong number\n");
   getch();
}


Output







Find Fibonacci Series Using Recursion in C Programming

It is sample C program which demonstrate how to use recursion concept in c programming. Here is a recursion program which accept a number from user and generate Fibonacci series using recursion.

Program Code
//Find Fibonacci Series Using Recursion in C Programming
#include"stdio.h"
#include"conio.h"
fibonacci(int n);
void main()
{
 int n,r,i;
 clrscr();
 printf("********** Fibonacci Series Using Recursion *********\n");
 printf("enter a number: ");
 scanf("%d",&n);
 printf("\n\n");

 for(i=0;i<=n;i++)
 {
  r=fibonacci(i);
  printf("\t%d",r);
 }
 getch();
}

fibonacci(int n)
{
 int f;
 if((n==1)||(n==2))
  return(1);
 else if(n==0)
  return(0);
 else
  f=fibonacci(n-2)+fibonacci(n-1);
 return(f);
}
Output






C Program With Recursion: Find Factorial Using Recursion in C Programming

It is a sample program example which demonstrate recursion in C programming. It is a factorial program with recursion. Accept number from the user and generate factorial of accepted number using recursion.

Program Code
#include"stdio.h"
#include"conio.h"
fact(int n);
void main()
{
 int n,r;
 clrscr();
 printf("************* Find Factorial of Number Using Recursion *************");
 printf("\n enter a number ");
 scanf("%d",&n);
 r=fact(n);
 printf("\n Factorial of %d is =  %2d\t",n,r);
 getch();
}

fact(int n)
{
 int f;
 if((n==0)||(n==1))
  return(1);
 else
  f=n*fact(n-1);
 return(f);
}



Output

Friday, November 18, 2011

Function Example in PL/SQL Oracle

It is a sample pl/sql oracle example which have a function cube1 and a program. When a function calls accepted number(no) from user is passed as a argument and output of cube1 function is return value to variable(res).


Aim - PL/SQL program to accept a number from user and display its cube(num^3) value using function.


Function:-
First Execute Function PL/SQL block
create or replace function cube1(no in number) return number IS result number(8);
begin
  result:=(no*no*no);
  return result;
exception
  when no_data_found then
  return 'error';
end;


Program: -
Second Execute PL/SQL Program
declare
 no number(5);
 res number(10);
begin
  no:=&no;
  res:=cube1(no);
  dbms_output.put_line('Cube of ' || no || ' is '|| res);
end;


Output: -
Enter value for no: 6
old 5: no:=&no;
new 5: no:=6;
Cube of 6 is 216