Pages

Saturday, 3 November 2012

PALINDROME NUMBERS




#include<stdio.h>

main()
{
   int n, reverse = 0, temp;

   printf("Enter a number to check if it is a palindrome or not\n");
   scanf("%d",&n);

   temp = n;

   while( temp != 0 )
   {
      reverse = reverse * 10;
      reverse = reverse + temp%10;
      temp = temp/10;
   }

   if ( n == reverse )
      printf("%d is a palindrome number.\n", n);
   else
      printf("%d is not a palindrome number.\n", n);

   return 0;
}


MATRIX ADDITION


/* Matrix Addition*/



#include <stdio.h>


main()
{
   int m, n, c, d, first[10][10], second[10][10], sum[10][10];

   printf("Enter the number of rows and columns of matrix ");
   scanf("%d%d", &m, &n);
   printf("Enter the elements of first matrix\n");

   for ( c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
         scanf("%d", &first[c][d]);

   printf("Enter the elements of second matrix\n");

   for ( c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
            scanf("%d", &second[c][d]);

   for ( c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
         sum[c][d] = first[c][d] + second[c][d];

   printf("Sum of entered matrices:-\n");

   for ( c = 0 ; c < m ; c++ )
   {
      for ( d = 0 ; d < n ; d++ )
         printf("%d\t", sum[c][d]);

      printf("\n");
   }

   return 0;
}






Saturday, 15 September 2012

QUADRATIC EQUATION

/* Quadratic Equation*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,d;
float r1,r2,s;
printf("enter a,b,c");
scanf("%d%d%d",&a,&b,&c);
d=b*b-(4*a*c);
s=sqrt(d);
if(d>=0)
{
r1=(-b+s)/(2*a);
r2=(-b-s)/(2*a);
if(r1==r2)
{
printf("the roots are real and equal\n");
printf("the root is %5.3f\n",r1);
}
else
printf("the roots are real and distinct\n");
printf("the roots are %5.3f and %5.3f\n",r1,r2);
}
else
printf("imaginary roots\n");
}

SUM AND REVERSE OF A NUMBER

/*Sum And Reverse Of A Number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0,rev=0,r;
printf("enter the number");
scanf("%d",&n);
while(n>0)
{
r=n%10;
rev=(rev*10)+r;
sum=sum+r;
n=n/10;
}
printf("sum is %d",sum);
printf("\n reverse is %d",rev);
getch();
}


FACTORIAL OF A NUMBER


/*Factorial Of A Number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,fact=1,i=1;
printf("enter number");
scanf("%d",&n);
while(i<=n)
{
fact=fact*i;
i++;
}
printf("factorial is %d",fact);
getch();
}

ARITHMETIC OPERATIONS

/*Arithmetic Operations*/ 

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
int ch;
printf("enter the numbers");
scanf("%d%d",&a,&b);
printf("enter your choice");
Printf("1.multiplication,2.division,3.addition,4.subtraction");
scanf("%d",&ch);
if(ch>0)
{
if(ch==1)
{
printf("product=%d",a*b);
}
else
if(ch==2)
{
printf("quotient=%d",a/b);
}
else
if(ch==3)
{
printf("sum=%d",a+b);
}
else
if(ch==4)
{
printf("diff=%d",a-b);
}
else
printf("Invalid choice");
getch();
}
}



AMICABLE NUMBERS



/*Amicable Numbers*/


#include<stdio.h>
#include<conio.h>
void main()
{
int i,r=0,sum=0,sum1=0,a,b,temp,temp1;
printf("Enter first number\n");
scanf("%d",&a);
printf("Enter second number\n");
scanf("%d",&b);
temp=a;
for(i=1;i<=a/2;i++)
{
r=a%i;
if(r==0)
sum+=i;
}
temp=b;
for(i=1;i<=b/2;i++)
{
r=b%i;
if(r==0
sum1+=i;
}
if((sum==temp1)&&(sum==temp))
printf("amicable");
else
printf("not amicable");
getch();
}