Tuesday, April 23, 2013

Function: Check Palindrom number or Not by using function in C

Write a C program to  Check Palindrom number or Not by using function in C

#include<stdio.h>
#include<conio.h>
int rev_check(int n)
{
int rev,temp=0,a=10;
while(n>0)
{
rev=n%a;
n=n/a;
temp=temp*a+rev;
}
return(temp);
}
main()
{
int n;
printf("\nEnter the number: ");
scanf("%d",&n);
if(rev_check(n)==n)
printf("\nThe given number is a palindrome\n");
else
printf("\nthe given number is not a palindrome\n");
}

Function: Check Prime number or Not by using Function in C

Check Prime number or Not by using Function



#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
    int prime(int x);
    int n,flag;
    printf("Enter the number: ");
    scanf("%d",&n);
    flag=prime(n);
    if(flag==1)
printf("\n Yes!! %d is Prime number \n",n);
    else
printf("\n No!! %d is not Prime number \n",n);
    }
int prime(int x)
{
       int i,a;
a=sqrt(x);
       if((x==1)||(x==2))
 return(0);
       else
       {
    for(i=2;i<=a;i++)
if(x%i==0)
   return(0);
    return(1);
}
}

Sum the Series: Sum=x1 + x1/2 + x1/3 + …. + x1/n

Write a C program to Calculate the below Series. The Value of x and n must take from input terminal.

Sum=x1 + x1/2 + x1/3  + ….  +  x1/n 



#include<stdio.h>
#include<conio.h>
main()
{
    int i,x,n,j;
    float sum=0.0,a=1.0,r,y;
    printf("Enter the value of X:");
    scanf("%d",&x);
    printf("\nEnter the range value for series:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        y=a/i;
        r=x*y;
        sum=sum+r;
    }
    printf("\nThe sum is:");
    printf("%f\n",sum);
}
 

Sum the Series: Sum = x + x2 + x3 +…. + xn

Write a C program to Calculate the below Series. The Value of x and n must take from input terminal.

  Sum = x + x2 + x3 +…. +  xn




#include<stdio.h>
main()
{
    int i,n,x,r=1,sum=0;
    printf("Enter the value of X:");
    scanf("%d",&x);
    printf("\nEnter the value of range for series:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        r=r*x;
        sum+=r;
    }
    printf("\nThe sum is:");
    printf("%d\n",sum);
}
 

Sum the series: sum= x+2x+3x+.......+xn

Write a C program to Calculate the below Series. The Value of x and n must take from input terminal.

Sum = x+2x+3x+.......+xn

 


#include<stdio.h>
main()
{
    int x,i,n,r,sum=0;
    printf("Enter the value of X:");
    scanf("%d",&x);
    printf("\nEnter the range value for series:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        r=i*x;
        sum+=r;
    }

   printf("\nThe sum is:);
    printf("%d\n",sum);
}
 

Find out the Multiple Number

Multiple Number




#include<stdio.h>
main()
{
int a, b;
printf("Enter the value of a and b:\n");
//while(scanf("%d %d", &a, &b)==2)
scanf("%d %d",&a,&b);
{
if(a%b==0||b%a==0)
{
printf("The given number is Multiple\n");
}
else
{
printf("The given number is not Multiple\n");
}
}
return 0;
}