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

Saturday, February 14, 2015

C Program to find sum of first n natural number


#include<iostream.h>
#include<conio.h>
void main()
{       clrscr();
int i,n,sum=0;
cout<<"How many numbers? ";
cin>>n;
for(i=1;i<=n;++i)
{
sum+=i;
cout<<"
SUM="<<sum<<endl;
}
getch();
}
Read more »

Friday, February 13, 2015

Java program to check whether a given number is palindrome or not

Java program to check whether a given number is palindrome or not

class Palindrome
{
public static void main(String...s)
{
int n,m,rev=0,i;
n=Integer.parseInt(s[0]);
m=n;

while(n!=0)
{
i=n%10;
rev=(rev*10)+i;
n/=10;
}

if(m==rev)
System.out.println("
Number is 


palindrome");
else
System.out.println("
Number is not 


palindrome");
}
}
Read more »

Thursday, February 12, 2015

C program to find whether a given number is an Armstrong number or not

C program to find whether a given number is an Armstrong number or not

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int n,m=0,x,y;
clrscr();
printf("Enter any three digit numnber:");
scanf("%d",&n);
y=n;

while(n!=0)
{
x=n%10;
m+=pow(x,3);
n=n/10;
}

if(y==m)
printf("The given number is an Armstrong number");
else
printf("The given number is not an Armstrong number");
getch();
}
Read more »