This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Showing posts with label C PROGRAM. Show all posts
Showing posts with label C PROGRAM. Show all posts

Thursday, November 22, 2012

C PROGRAM FOR FACTORIAL USING RECURSION


/* C PROGRAM FOR  FACTORIAL USING RECURSION */

#include<stdio.h>
#include<conio.h>

void main()
{
      int n,f;
      int fact(int);
      clrscr();
      printf("\n\t\t FACTORIAL USING RECURSION");
      printf("\n\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~");
      printf("\n Enter the numbers:");
      scanf("%d",&n);
      f=fact(n);
      printf("\n The factorial :%d",f);
      getch();
 }

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






















OUTPUT:

              
                     FACTORIAL USING RECURSION



Enter the numbers: 5

 The factorial: 120






C PROGRAM FOR FIBONNACCI USING RECURSION


/*C PROGRAM FOR FIBONNACCI USING RECURSION */

# include<stdio.h>
# include<conio.h>

void main()
{
 void fib(int);
          int n;
         clrscr();
         printf("\n\t\FIBONACCI USING RECURSION");
         printf("\n\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~");
         printf("\nEnter the number of terms : ");
         scanf("%d",&n);
         fib(n);
        getch();
 }

void fib(int d)
 {
 int i,t,a=0,b=1;
             if(d==1)
             {
             printf("%d",a); }

 else if (d==2)
 {
      printf("%d \t %d",a,b);
   }
 else
 {
       printf("%d \t %d",a,b);
       for(i=2;i<d;i++)
{
       t=a+b;
       printf("\t%d",t);
       a=b;
        b=t;
     }
   }
}






OUTPUT:

                FIBONACCI USING RECURSION
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter the number of terms: 6

0        1      1       2       3       5




C PROGRAM FOR FIBONNACI SERIES


/*C PROGRAM FOR   FIBONNACI SERIES */


#include<stdio.h>
#include<conio.h>

void main()
{
       int i,a=0,b=1,t=0,n;
       clrscr();
       printf("\n\t\tFIBONNACI SERIES");
       printf("\n\t\t~~~~~~~~~~~~~~~~");
       printf("\nEnter the number of terms:");
       scanf("%d",&n);
       printf("%d\t%d",a,b);

for(i=2;i<n;i++)
{
       t=a+b;
       printf("\t%d",t);
       a=b;
       b=t;
   }
   getch();
}























OUTPUT:


                FIBONNACI SERIES
                ~~~~~~~~~~~~~~~~

Enter the number of terms:8


0       1       1       2       3       5       8       13












C PROGRAM FOR FLOYD’S TRIANGLE


 /* C PROGRAM FOR  FLOYD’S TRIANGLE */


#include<stdio.h>
#include<conio.h>

void main()
{
    int i,j,rows;
    clrscr();
    printf("\n\t\tFLOYD'S TRIANGLE");
    printf("\n\t\t~~~~~~~~~~~~~~~~");
    printf("\nEnter the rows:");
    scanf("%d",&rows);
    for(i=1;i<=rows;i++)
   {
     for(j=1;j<=i;j++)
     {
      printf("*");
    }
     printf("\n");
   }
  getch();
}
















OUTPUT:

                FLOYD'S TRIANGLE
               

Enter the rows: 5
*
**
***
****
*****


C PROGRAM FOR PASCAL TRIANGLE


/* C PROGRAM FOR  PASCAL TRIANGLE*/

#include<stdio.h>
#include<conio.h>

void main()
{
      int a[10][10],r,i,j,t;
      clrscr();
      printf("\n\t\t PASCAL TRIANGLE");
      printf("\n\t\t ~~~~~~~~~~~~~~~~");
      printf("\n Enter the row values:");
      scanf("%d",&r);

for(i=1;i<=r;i++)
 {
       a[i][i]=1;
       a[i][1]=1;
  }
  i=3;
  while(i<=r)
   {
      t=2;
while(t<i)
{
      a[i][t]=a[i-1][t-1]+a[i-1][t];
      t++;
    }
     i++;
}
for(i=1;i<=r;i++)
{
for(j=1;j<=i;j++)
{
     printf("%d\t",a[i][j]);
   }
    printf("\n\n");
   }
  getch();
}







OUTPUT:

                 PASCAL TRIANGLE
                 ~~~~~~~~~~~~~~~~
 Enter the row values: 5
1

1       1

1       2       1

1       3       3       1

1       4       6       4       1


C PROGRAM FOR COSINE SERIES


/*C PROGRAM FOR  COSINE SERIES */

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define pi 3.14

void main()
{
    int n,i,j;
    float x,x1,sum,p,f,k;
    clrscr();
    printf("\n\tCOSINE SERIES");
    printf("\n\t~~~~~~~~~~~~~~~");
    printf("\nEnter the value of n:");
    scanf("%d",&n);
    printf("\nEnter the value for x:");
    scanf("%f",&x);
    x1=x*(pi/180);
    sum=1;

for(i=2;i<=n*2;i+=2)
{
     p=pow(x1,i);
     f=1;

for(j=1;j<i;j++)
{
     f=f*j;
}
     k=1;
     k=k*(-1);
     sum=sum+(p/f)*k;
}
     printf("\n The sum of series %f",sum);
     printf("\n The cosine series:%f",cos(x1));
     getch();
}









OUTPUT:

        COSINE SERIES
        ~~~~~~~~~~~~~~
Enter the value of n: 2

Enter the value for x: 4

 The sum of series: 0.995127
 The cosine series: 0.997567



C PROGRAM FOR EXPONENTIAL SERIES


                                    /* C PROGRAM FOR  EXPONENTIAL SERIES*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define pi 3.14

void main()
{
       int n,i,j;
       float x,sum,p,f;
       clrscr();
       printf("\n\tEXPONENTIAL SERIES");
       printf("\n\t~~~~~~~~~~~~~~~~~~");
       printf("\n Enter the value of n:");
       scanf("%d",&n);
       printf("\n Enter the value for x:");
       scanf("%f",&x);
       x=x*(pi/180);
       sum=1;

for(i=1;i<=n;i++)
{
       p=1;
       f=1;

for(j=1;j<=i;j++)
{
       p=p*x;
       f=f*j;
}
       sum=sum+(p/f);
  }
       printf("\n The sum of series: %f",sum);
       printf("\n The cosine series: %f",exp(x));
getch();
}











OUTPUT:
        EXPONENTIAL SERIES
        ~~~~~~~~~~~~~~~~~~~~~~
 Enter the value of n: 4

 Enter the value for x: 6

 The sum of series: 1.110340
 The cosine series: 1.110340



C PROGRAM FOR SINE SERIES


                             /*  C PROGRAM FOR SINE SERIES*/


#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
      int n,i,j,k,f;
      float x,x1,sum,p;
      clrscr();
      printf("\n\t SINE SERIES\n");
      printf("\n\t~~~~~~~~~~~~~~~");
      printf("\n Enter the value of n:");
      scanf("%d",&n);
      printf("\n Enter the value of x:");
      scanf("%f",&x);
      x1=x*(3.14/180);
      sum=x1;
      for(i=3;i<=n*2;i+=2)
     {
       p=pow(x1,i);
       f=1;
       for(j=1;j<=i;j++)
       {
        f=f*j;
       }
       k=-1;
       k=k*(-1);
       sum=sum+(p/f)*k;
     }
     printf("\n Sum of the series:%f",sum);
     printf("\n Sine series value:%f",sin(x1));
     getch();
}












OUTPUT:
         SINE SERIES
        ~~~~~~~~~~~
 Enter the value of n:2

 Enter the value of x:3

 Sum of the series:0.052357

 Sine series value:0.052309


C PROGRAM FOR CONCATENATING TWO STRING


/*C PROGRAM FOR  CONCATENATING TWO STRING */

#include<stdio.h>
#include<conio.h>

void main()
{
    char s[30],s1[30],s2[30];
    int i,j;
    clrscr();
    printf("\n\t CONCATENATING TWO STRING");
    printf("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~");
    printf("enter the first string");
    scanf("%s",s);
    printf("enter the second string");
    scanf("%s",s1);
    for(i=0;s[i]!='\0';i++)
    s2[i]=s[i];
    for(j=0;s1[j]!='\0';j++)
    s2[i++]=s1[j];
    s2[i]='\0';
    printf("the concatenated string is %s",s2);
    getch();
}

























OUTPUT:

        
       
 CONCATENATING TWO STRING

Enter the first string: RAJ.

 Enter the second string: KUMAR

The concatenated string is: RAJKUMAR

C PROGRAM FOR FINDING THE SUBSTRING


/*  C PROGRAM FOR  FINDING THE SUBSTRING */

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
        char str[10],sstr[10];
        int m1,m2,i,j,temp;
        clrscr();
        printf("\n\t\t FINDING THE SUBSTRING");
        printf("\n\t\t ~~~~~~~~~~~~~~~~~~~~~~");
        printf("\n Enter the string:");
        scanf("%s",str);
        printf("\n Enter the substring:");
        scanf("%s",sstr);
        m1=strlen(str);
        m2=strlen(sstr);
        j=0;
for(i=0;i<=m1;i++)
{
      if(str[i]==sstr[j])
      j++;
      else
      j=0;
      if(j==m2)
      temp=0;
  }
      if(temp==0)
      printf("\nThe string is found:");
      else
      printf("\nThe string is not found:");
      getch();
  }














OUTPUT:
                 FINDING THE SUBSTRING
                 ~~~~~~~~~~~~~~~~~~~~~~
 Enter the string: GOODMORNING

 Enter the substring: GOOD

The string is found.


C PROGRAM FOR REVERSING THE STRING


/*  C PROGRAM FOR REVERSING THE STRING */
#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
       int n,i;
      char a[20];
      clrscr();
      printf("\n\t\tREVERSING THE STRING");
      printf("\n\t\t--------------------");
      printf("\n\t\tINPUT");
      printf("\n\t\t-----");
      printf("\nEnter the string:");
      scanf("%s",a);
      n=strlen(a);
      printf("\n\t\tOUTPUT");
      printf("\nThe result is:");

    for(i=n;i>=0;i--)
    {
       printf("%c",a[i]);
     }
 getch();
}


           

















OUTPUT:


     REVERSING THE STRING
                --------------------
                INPUT
                     Enter the string:RAJKUMAR
               OUTPUT
                   The result is: RAMUKJAR

C PROGRAM FOR FINDING LENGTH OF THE STRING



/*C PROGRAM FOR FINDING LENGTH OF THE STRING*/

#include<stdio.h>
#include<conio.h>

void main()
{
      char str[50];
      int k;
      clrscr();
      printf("\n\t FINDING LENGTH OF THE STRING");
      printf("\n\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
      printf("\n Enter the string:");
      gets(str);
      k=0;
      while(str[k]!='\0')
       k++;
      printf("\n The length is %d",k);
      getch();
}





























OUTPUT:
        FINDING LENGTH OF THE STRING
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
 Enter the string: KRK

 The length is : 3