Important programs in c language part-II

/*Deletion in the Array*/

#include<stdio.h>
#include<conio.h>
int i,n;
main()
{
int a[100],pos;
void delete(int a[],int,int);
clrscr();
printf("How many elements in the array\n");
scanf("%d",&n);
printf("Enter the element of the array\n");
for(i=0;i<=n-1;i++)
scanf("%d",&a[i]);
printf("On which postion element do you want delete\n");
scanf("%d",&pos);
delete(a,pos,n);
getch();
}
void delete(int a[],int pos,int n)
{
int j,item;
item=a[pos];
for(j=pos;j<=n-1;j++)
{
a[j]=a[j+1];
}
n=n-1;
for(i=0;i<=n-1;i++)
printf("%d\n",a[i]);
}

/*Factorial*/

#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
 int n,result;
 clrscr();
 printf("Enter the number");
 scanf("%d",&n);
 result=fact(n);
 printf("\n The factorial of %d is %d",n,result);
 getch();
 }
int fact(int x)
{
 int f;
 if(x==1)
  {
    return(x);
    }
 else
  {
    return(x*fact(x-1));
   }
}

/*Fibonaci series*/

#include<stdio.h>
# include<conio.h>
void main()
{
int a[100],i,n;
clrscr();
printf("Enter the no. of elements in the series :\n ");
scanf("%d",&n);
a[0]=0;
a[1]=1;
for(i=2;i<=n-1;i++)
 {
  a[i] = a[i-2] + a[i-1];
 }
printf("Fibonacci Series is : \n");
  for(i=0;i<=n-1;i++)
   {
    printf("%d\n",a[i]);
   }
getch();
}

Leave a Reply

You must be logged in to post a comment.

Close