Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

4a Write a sample code to check whether the given number is an 

armstrong
number or not.
#include<stdio.h>
#include<math.h>
void main(){
int n, count=0,n1,n2,rem,ams=0;
printf("Enter any number : ");
scanf("%d", &n);
n1=n;
n2=n;
while(n2>0){
rem=n2%10;
count++;
n2=n2/10;
}
while(n1>0){
rem=n1%10;
ams=ams+pow(rem,count);
n1=n1/10;
}
if(n==ams)
printf("The given number %d is an armstrong number\n",n);
else
printf("The given number %d is not an armstrong number\n",n);
}
4b Write a sample program to check whether the given number is a prime
number or not.
#include<stdio.h>
void main()
{
int n,i,flag=0;
printf("Enter any number : ");
scanf("%d",&n);
for(i=2;i<n/2;i++)
{
if(n%i==0)
flag=1;
}
if(flag==0)
printf("The given number %d is a prime number\n",n);
else
printf("The given number %d is not a prime number\n",n);
}
4c Write a C program to calculate the following series value, where x is a
fractional value.
1- X2/2! + X4/4! - X6/6! + X8/8! - X10/10!

#include<stdio.h>
void main()
{
float x,i,t,s=1;
printf("Enter value of x : ");
scanf("%f",&x);
t=1.0;
for(i=2;i<=10;i+=2)
{
t=(t*(-1)*x*x)/(i*(i-1));
s=s+t;
}
printf("Sum of series : %f\n",s);
}
4d Write a C program to find the number of even and odd digits in a
given number.
#include<stdio.h>
void main()
{
int n,n1,Ecount=0,Ocount=0;
printf("Enter the number: ");
scanf("%d",&n);
while(n>0)
{
n1=n%10;
if(n1%2==0)
Ecount++;
else
Ocount++;
n=n/10;
}
printf("Number of even digits: %d\n",Ecount);
printf("Number of odd digits: %d\n",Ocount);
}

You might also like