Tuesday, October 4, 2011

Factorial

Program       :   Write a program to calculate factorial of given number
Created By  :   JABIR PATHAN 

#include<stdio.h>
#include<conio.h>
long int fact(int);
void main()
{
  int no;
  clrscr();
  printf("enter any number==>");
  scanf("%d",&no);
  printf("the factorial of entered number==>%d",fact(no));
  getch();
}



long int fact(int num)
 {
   if(num==1)
      return(1);
   else
      return(num*fact(num-1));
 }


Prime numbers


Program      :  Write a c program to generate all prime numbers between 1 to n.
Crated By   :  JABIR  PATHAN

#include<stdio.h>
#include<conio.h>
void main()
{
    int no,i;
    clrscr();
    printf("Enter any number or Range==>");
    scanf("%d",&no);
    for(i=1;i<=no;i++)
    {
      if(i==1||i==2||i==3||i==5||i==7)
      {
        printf("\t%d",i);
      }
     else
        if(i%2>0&&i%3>0&&i%5>0&&i%7>0)
        {
           printf("\t%d",i);
         }
    }
   getch();
  }

Monday, October 3, 2011

Bubble Sort

Program       :  Write a program in C to Sort N Integer Using Bubble Sort
Created By  :  JABIR PATHAN

#include<stdio.h>
#include<conio.h>
void main()
{
   int arr[100],i,j,temp,n;
   clrscr();
   printf("Enter the How many Elements you want to enter in array==>");
   scanf("%d",&n);
   for(i=0;i<=n-1;i++)
   {
     printf("\nEnter elements for arr[%d]=",i);
     scanf("%d",&arr[i]);
   }
   printf("\n\nAccepted Array Elements Are==>\n ");
   for(i=0;i<=n-1;i++)
    {
      printf("\n arr[%d]=%d",i,arr[i]);
    }

   for(i=0;i<=n-1;i++)
    {
      for(j=0;j<=n-1;j++)
       {
          if(arr[j]>arr[i])
           {
              temp=arr[i];
              arr[i]=arr[j];
              arr[j]=temp;
           }
      }
  }
 printf("\n\n\nThe content of an array in an ascending order are==>\n");

 for(i=0;i<=n-1;i++)
   {
     printf("\narr[%d]=%d",i,arr[i]);
   }
  getch();
}

Reverse the digits

Program      :   Write a program in c to reverse the digits of a given integer.
Created By :   JABIR PATHAN

#include<stdio.h>
#include<conio.h>
void main()
{
   int no,rem=0,cnt=0;
   clrscr();
   printf("Enter any Number==>");
   scanf("%d",&no);
   printf("The Reverse number is=");
   while(no!=0)
   {
     rem=no%10;
     cnt++;
     printf("%d",rem);
     no=no/10;
   }
   printf("\nTotal digit in given integer=%d",cnt);
   getch();
}

GCD

Program       :  Write a C Program to Compute GCD of Given Two Integers
Created By  :  JABIR PATHAN


#include<stdio.h>
#include<conio.h>
void main()
{
   int i,a,b,gcd,min;
   clrscr();
   printf("enter any two numbers==>\n");
   scanf("%d%d",&a,&b);
  i f(a<b)
   {
     min=a;
    }
   else
   {
    min=b;
   }
   for(i=1;i<=min;i++)
    {
       if(a%i==0&&b%i==0)
       {
         gcd=i;
      }
   }
   printf("gcd of %d and %d is==>%d",a,b,gcd);
   getch();
  }