Tuesday, 30 June 2015
Tuesday, 23 June 2015
WRITE A C PROGRAME TO FIND AMSTRONG NUMBER
#include<stdio.h>
int
main()
{
int n, n1, rem, num=0;
printf("Enter a positive integer value: ");
scanf("%d", &n);
n1=n;
while(n1!=0)
{
rem=n1%10;
num+=rem*rem*rem;
n1=n1/10;
}
if(n==num)
{
printf("%d is an
Armstrong number",n);
}
else
printf("%d is not
an Armstrong number",n);
}
OUTPUT
Enter a
positive integer value: 142
142 is
not an Armstrong number
Labels:
Amstrong number,
c program
C PROGRAM TO DISPLAY PRIME NUMBERS BETWEEN TWO NUMBERS
#include<stdio.h>
void main()
{
int a, b, i, j, flag;
printf("Enter two numbers : ");
scanf("%d %d", &a, &b);
printf("Prime numbers between %d and %d are : ", a, b);
for(i=a+1; i<b; ++i)
{
flag=0;
for(j=2; j<=i/2; ++j)
{
if(i%j==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("%d ",i);
}
return 0;
}
OUTPUT
Enter two numbers :12
30
Prime numbers between 12 and 30 are : 13 17 19 23 29
C PROGRAM TO CHECK WETHER THE GIVEN NUMBER IS PRIME OR NOT
#include<stdio.h>
int main()
{
int n, i, flag=0;
printf("Enter a positive integer value : ");
scanf("%d",&n);
for(i=2;i<=n/2;++i)
{
if(n%i==0)
{
flag=1;
break;
}
}
if (flag==0)
printf("%d is a prime number.",n);
else
printf("%d is not a prime number.",n);
return 0;
}
OUTPUT
Enter a positive integer value : 8
8 is not a prime number
C PROGRAM TO FIND POWER OF A NUMBER
#include <stdio.h>
int main()
{
int base, exp;
long long int n=1;
printf("Enter base value and exponent value : ");
scanf("%d %d", &base, &exp);
while (exp!=0)
{
n = n * base;
--exp;
}
printf("Answer : %d", n);
}
OUTPUT
Enter base value and exponent value :5
8
Answer :390625
C PROGRAM TO REVERSE A GIVEN NUMBER
#include <stdio.h>
int main()
{
int n, rvs=0, rem;
printf("Enter an integer value : ");
scanf("%d", &n);
while(n!=0)
{
rem=n%10;
rvs=rvs*10+rem;
n=n/10;
}
printf("Reversed number : %d",rvs);
return 0;
}
OUTPUT
Enter an integer value : 58
Reverse number : 85
Subscribe to:
Comments (Atom)