Showing posts with label Armstrong number. Show all posts
Showing posts with label Armstrong number. Show all posts

Saturday, December 24, 2011

Check Whether Given Number is Armstrong or Not in C Program

It is a sample c program to check whether given number is Armstrong or not.

Program Source Code


#include"stdio.h"
#include"conio.h"
#include"math.h"
void main()
{
int number, a , i , j , sum=0 , count=0;
clrscr();
printf(“Enter any number”);
scanf(“%d”, &number);
i=number;
j=number;
while(j>0)
{
j=j%10;
count++;
}
while(i>0)
{
a=i%10;
sum=sum + pow(a, count);
i=i/10;
}
if(sum==number)
printf(“%d is a Armstrong number”, number);
else
printf(“%d is a not Armstrong number”, number);
getch();
}

Output


Armstrong or Not in C Program

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







Thursday, November 17, 2011

Check Number is Armstrong in PL/SQL Programming

It is a sample pl/sql program to take input a number from user and it checks accepted number is Armstrong or not.

Aim - PL/SQL program to check whether number is Armstrong or not.

Program:-
declare
  pnum number(5);
  tot number(5);
  lp number(3);
  tmp number(5);
begin
  pnum:=&pnum;
  tmp:=pnum;
  tot:=0;
  while tmp>0
  loop
    lp:=tmp mod 10;
    tot:= tot + (lp*lp*lp);
    tmp:=floor(tmp/10);
  end loop;
  if(tot like pnum) then
    dbms_output.put_line(pnum||' is armstrong.');
  else
    dbms_output.put_line(pnum||' is not armstrong.');
  end if;
end;


Output: -
Enter value for pnum: 153
old 7: pnum:=&pnum;
new 7: pnum:=153;
153 is armstrong.