Pages

Tuesday, 25 December 2012

CALCULATOR USING SWITCH CASE



/* Calculator using Switch Case */
#include<stdio.h>
#include<stdlib.h>
void main()
 {
  int a,b,c;
  float s;
  printf("\nEnter two numbers:");
  scanf("%d%d",&a,&b);
  printf(" 1.Addition  \n 2.Subtraction \n  3.multiplication \n  4.Division  \n  5.Exit \n");
  printf("\nEnter the choice:");
  scanf("%d",&c);

     switch(c)
      {
        case 1:printf("The sum is %d",a+b);
                break;
        case 2:printf("The Subtraction is %d",a-b);
                break;
        case 3:printf("The multiplication is %d",a*b);
                break;
        case 4:s=a/b;
                printf("The Division is %f",s);
                break;
        case 5:exit(0);
        default:printf("Invalid Option");
                break;
      }
 }


FACTORIAL OF A NUMBER



/* Factorial Of A Number */
#include<stdio.h>
void main()
 {
  int n,f=1,i=1;
  printf("Enter the number:\n");
  scanf("%d",&n);
    while(i<=n)
     {
      f=f*i;
      i++;
     }
  printf("Factorial of the number is %d",f);
}


REVERSE OF A NUMBER



/* Reverse Of A Number */
#include<stdio.h>
#include<math.h>
void main()
 {
  int n,rev=0,sum=0,r;
  printf("Enter the number");
  scanf("%d",&n);
  while(n!=0)
   {
    r=n%10;
    rev=(rev*10)+r;
    sum=r+sum;
    n=n/10;
   }
  printf("Reverse is %d ",rev);
  printf("Sum of digit is %d",sum);
}




TEMPERATURE CONVERSION


/* Temperature Conversion */
#include<stdio.h>
void main()
 {
  int t,k;
  float f;
  printf("Enter the temperature which you want to covert:\n");
  scanf("%d",&t);
  k=t+273;
  f=(t+32)*5/9;
  printf("The fareheit scale is %f and kelvin scale is %d",f,k);
 }



SIMPLE CALCULATOR



/* simple calculator */
#include<stdio.h>
#include<string.h>
void main()
 {
  int a,b;
  printf("Enter two Numbers:");
  scanf("%d%d",&a,&b);
 /* printf("Enter the operation you need:\n");
  scanf("%c",op);*/


    printf("The sum is %d\n",a+b);

    printf("The Difference is %d\n",a-b);

    printf("The Division is %d\n",a/b);

    printf("The Multiplication is %d\n",a*b);

 }


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;
}