Custom Search
Showing posts with label C Programs. Show all posts
Showing posts with label C Programs. Show all posts

Sunday, 22 January 2012

Write a c program to delete an element from array


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com


#include<stdio.h>
#include<conio.h>
 
void main()
{
      int array[100], position, c, n;
 
      printf("Enter number of elements in array\n");
      scanf("%d", &n);
 
      printf("Enter %d elements\n", n);
 
      for ( c = 0 ; c < n ; c++ )
          scanf("%d", &array[c]);
 
      printf("Enter the location where you wish to delete element\n");
      scanf("%d", &position);
 
      if ( position >= n+1 )
          printf("Deletion not possible.\n"); 
      else
      {
          for ( c = position - 1 ; c < n - 1 ; c++ )
              array[c] = array[c+1];
 
          printf("Resultant array is\n");
 
          for( c = 0 ; c < n - 1 ; c++ )
              printf("%d\n", array[c]);
      }
 
     getch();
}
Read more

Saturday, 21 January 2012

Write a c program to add 2 numbers using pointers

Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

#include<stdio.h>
#include<conio.h>
void main()
{
   int first, second, *p, *q, sum;
 
   printf("Enter two integers to add\n");
   scanf("%d%d", &first, &second);
 
   p = &first;
   q = &second;
 
   sum = *p + *q;
 
   printf("Sum of entered numbers = %d\n",sum);
 
   getch()
}
Read more

Write a c program to print pascals triangle

Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

#include<stdio.h>
#include<conio.h>
long factorial(int);

void main()
{
   int i, n, c;
 
   printf("Enter the number of rows you wish to see in pascal triangle\n");
   scanf("%d",&n);
 
   for ( i = 0 ; i < n ; i++ )
   {
      for ( c = 0 ; c <= ( n - i - 2 ) ; c++ )
         printf(" ");
 
      for( c = 0 ; c <= i ; c++ )
         printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));
 
      printf("\n");
   }
 getch()
  
}
 
long factorial(int n)
{
   int c;
   long result = 1;
 
   for( c = 1 ; c <= n ; c++ )
         result = result*c;
 
   return ( result );
}
Read more

Write a c program to convert decimal to binary

Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

#include<stdio.h>
#include<conio.h>
void main()
{
   int n, c, k;
 
   printf("Enter an integer in decimal number system\n");
   scanf("%d",&n);
 
   printf("%d in binary number system is:\n", n);
 
   for ( c = 31 ; c >= 0 ; c-- )
   {
      k = n >> c;
 
      if ( k & 1 )
         printf("1");
      else
         printf("0");
   }
 
   printf("\n");
 
   getch()
}
Read more

Tuesday, 17 January 2012

C Program to find factorial


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

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

void main()
{
int i,f=1,num;
clrscr();
  printf("Enter a number: ");
scanf("%d",&num);
  for(i=1;i<=num;i++)
{f=f*i;}
printf("Factorial of %d is: %d",num,f);
getch();
}
Read more

Thursday, 22 December 2011

Q11)Write a program to find factorial,power and fibonacci series using recursion


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

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

int fibonacci(int);
int factorial(int);
int power(int,int);
void main()
{
 clrscr();
 int c,f,i=1,m,x,p,n,ch;
 do
 {
  printf("\n\n\t\t[ menu ]\n");
  printf(" 1.fibonacci\n 2.factorial\n 3.power\n");
  printf("enter your choice : ");
  scanf("%d",&c);
  switch(c)
  {
   case 1:
    printf("\n\nenter the limit : ");
    scanf("%d",&p);
    printf("\nfibonacci series : ");
    while(i<=p)
    {
     printf(" %d ",fibonacci(i));
     i++;
    }
    break;
   case 2:
    printf("\n\nenter a number : ");
    scanf("%d",&m);
    f=factorial(m);
    printf("\nfactorial = %d",f);
    break;
   case 3:
    printf("\nenter the value of x and n : ");
    scanf("%d %d",&x,&n);
    p=power(x,n);
    printf("\n\t%d^%d = %d",x,n,p);
    break;
   default:
    printf("\n\ninvalid choice\n");
  }
  printf("\n\nif you wants to continue press 1 otherwise press 0 : " );
  scanf("%d",&ch);
 }while(ch==1);
 getch();
}
 int fibonacci(int p)
 {
  if(p==1)
   return 0;
  if(p==2)
   return 1;
  else
   return(fibonacci(p-2)+fibonacci(p-1));
 }
 int factorial(int m)
 {
  if(m==0)
   return 1;
  else
   return(m*factorial(m-1));
 }
 int power(int a,int b)
 {
  if(b==0)
   return 1;
  else
   return(a*power(a,b-1));
 }


Read more

Monday, 12 December 2011

Q10)write a program to add 2 matrices using pointers


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

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

#include<stdlib.h>
void main()
{
 clrscr();
 int *a[10],*b[10],*c[10];
 int m,n,p,q,i,j;
 printf("\nenter order of first matrix : ");
 scanf("%d %d",&m,&n);
 printf("\nenter order of second matrix : ");
 scanf("%d %d",&p,&q);
 if((m!=p)&&(n!=q))
 printf("\n\naddition not possible\n");
 else
 {
  for(i=0;i
  {
   a[i]=(int *)malloc(n*sizeof(int));
   b[i]=(int *)malloc(n*sizeof(int));
   c[i]=(int *)malloc(n*sizeof(int));
  }
  printf("\nenter elements of first matrix : ");
  for(i=0;i
  {
   for(j=0;j
   {
    scanf("%d",a[i]+j);
   }
  }
  printf("\nenter elements of second matrix : ");
  for(i=0;i

  {
   for(j=0;j
   {
    scanf("%d",b[i]+j);
   }
  }
  printf("\n\nfirst matrix :\n");
  for(i=0;i
  {
   for(j=0;j
   {
    printf(" %d ",*(a[i]+j));
   }
   printf("\n");
  }
  printf("\nsecond  matrix :\n");
  for(i=0;i

  {
   for(j=0;j
   {
    printf(" %d ",*(b[i]+j));
   }
   printf("\n");
  }
  for(i=0;i
  {
   for(j=0;j
   {
   *(c[i]+j)=*(a[i]+j)+*(b[i]+j);
   }
  }
  printf("sum of two matrices \n");
  for(i=0;i
  {
   for(j=0;j
   {
    printf("%d ",*(c[i]+j));
   }
   printf("\n");
  }
 }
 getch();
}

Read more

Q9)write a program to find row sum and column sum of a matrix


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

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

void main()
{
 clrscr();
 int a[25][25],m,n,i,j,rowsum,columnsum;
 printf("\nenter the order of matrix : ");
 scanf("%d %d",&m,&n);
 printf("\nenter the elements of matrix : ");
 for(i=0;i
 {
  for(j=0;j
  {
   scanf("%d",&a[i][j]);
  }
 }
 printf("\n\n matrix :\n");
 for(i=0;i
 {
  for(j=0;j
  {
   printf(" %d ",a[i][j]);
  }
  printf("\n");
 }
 for(i=0;i
 {
  rowsum=0;
  for(j=0;j
  {
   rowsum=rowsum+a[i][j];
  }
  printf("\nsum of the row %d = %d\n",i+1,rowsum);
 }
 for(j=0;j
 {
  columnsum=0;
  for(i=0;i
  {
   columnsum=columnsum+a[i][j];
  }
  printf("\nsum of the column %d =%d\n",j+1,columnsum);
 }
 getch();
}

Read more

Q8)write a program to find the transpose of a matrix


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

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

void main()
{
 clrscr();
 int a[20][20],m,n,i,j;
 printf("\nenter the order of the matrix : ");
 scanf("%d %d",&m,&n);
 printf("\nenter the elements of the matrix : ");
 for(i=0;i
 {
  for(j=0;j
  {
   scanf("%d",&a[i][j]);
  }
 }
 printf("\n\nmatrix is\n");
 for(i=0;i
 {
  for(j=0;j
  {
   printf(" %d ",a[i][j]);
  }
  printf("\n");
 }
 printf("\n\ntranspose of the matrix is\n");
 for(i=0;i
 {
  for(j=0;j
  {
   printf(" %d ",a[j][i]);
  }
  printf("\n");
 }
 getch();
}

Read more

Q7)Write a program to fing the product of 2 matrices


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

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

void main()
{
 clrscr();
 int m1[25][25],m2[25][25],m[25][25],r1,c1,r2,c2,i,j,k;
 printf("\nenter the order of first matrix : ");
 scanf("%d %d",&r1,&c1);
 printf("\nenter the order of second matrix : ");
 scanf("%d %d",&r2,&c2);
 if(r2==c1)
 {
  printf("\nenter the elements of first matrix : ");
  for(i=0;i
  {
   for(j=0;j
   {
    scanf("%d",&m1[i][j]);
   }
  }
  printf("\nenter the elements of second matrix : ");
  for(i=0;i
  {
   for(j=0;j
   {
    scanf("%d",&m2[i][j]);
   }
  }
  printf("\n\nfirst matrix : \n");
  for(i=0;i
  {
   for(j=0;j
   {
    printf(" %d ",m1[i][j]);
   }
   printf("\n");
  }
  printf("\nsecond matrix : \n");
  for(i=0;i
  {
   for(j=0;j
   {
    printf(" %d ",m2[i][j]);
   }
   printf("\n");
  }
  for(i=0;i
  {
   for(j=0;j
   {
    m[i][j]=0;
    for(k=0;k
     m[i][j]=m[i][j]+(m1[i][k]*m2[k][j]);
    }
  }
  printf("\nproduct of two matrices :\n");
  for(i=0;i
  {
   for(j=0;j
   {
    printf(" %d ",m[i][j]);
    printf(" ");
   }
Read more

Monday, 28 November 2011

Q6)Write a program to add 2 matrices?


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

#include<stdio.h>
#include<conio.h>
void main()
{
 clrscr();
 int m1[20][20],m2[20][20],s[20][20],i,j,m,n,p,q;
 printf("\nenter the order of the first matrix : ");
 scanf("%d %d",&m,&n);
 printf("\nenter the order of the second matrix : ");
 scanf("%d %d",&p,&q);
 if((m==p)&&(n==q))
 {
  printf("\n\nenter the elements of first matrix : ");
  for(i=0;i  for(j=0;j  scanf("%d",&m1[i][j]);
  printf("\nenter the elements of second matrix : ");
  for(i=0;i

  for(j=0;j  scanf("%d",&m2[i][j]);
  printf("\n\nfirst matrix : \n");
  for(i=0;i  {
   for(j=0;j   printf(" %d ",m1[i][j]);
   printf("\n");
  }
  printf("\nsecond matrix : \n");
  for(i=0;i
  {
   for(j=0;j   printf(" %d ",m2[i][j]);printf("\n");
  }
printf("\nsum of the two matrices :\n");
  for(i=0;i  {
   for(j=0;j   {
    s[i][j]=m1[i][j]+m2[i][j];
    printf(" %d ",s[i][j]);
   }
   printf("\n");
  }
  }
 else
 {
  printf("\n\n\naddition not possible");
  }
 getch();
}

Read more

Friday, 25 November 2011

Q5)write a program to generate sine and cosine series?


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

#include<stdio.h>
#include<conio.h>
void main()
{
 clrscr();
 float term,termc,sum=0,sumc=0,x,k=0,j=1;
 int n,c,i;
 printf("menu\n");
 printf("1.sine series\n2.cosine series\n");
 printf("enter your choice\n");
 scanf("%d",&c);
 printf("enter the angle in degree\n");
 scanf("%f",&x);
 printf("enter the number of terms\n");
 scanf("%d",&n);
 x=((x*3.14)/180);
 switch(c)
 {
  case 1:
    term=x;
    for(i=1;i<=n;i++)
    {
     sum=sum+term;
     j=j+2;
     term=((term*(-1)*x*x)/(j*(j-1)));
    }
    printf("sum of the sine series=%f\n",sum);
    break;
  case 2:
    termc=1;
    for(i=1;i<=n;i++)
    {
     sumc=sumc+termc;
     k=k+2;
     termc=((termc*(-1)*x*x)/(k*(k-1)));
    }
    printf("sum of the cosine series=%f",sumc);
    break;
  default:
    printf("invalid choice");
 }
 getch();
}
Read more

Q4)Write a program to generate fibonacci series


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

#include<stdio.h>
#include<conio.h>
void main()
{
 clrscr();
 int n,i=1,f1=0,f2=1,f3;
 printf("enter a number\n");
 scanf("%d",&n);
 printf("fibonacci series of%d numbers",n);
 while(i<=n)
 {
  printf("\n%d",f1);
  f3=f1+f2;
  f1=f2;
  f2=f3;
  i++;
 }
 getch();
}
Read more

Q3)Write a program to check wheather the given number is amstrong or not


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

#include<stdio.h>
#include<conio.h>
void main()
{
 clrscr();
 int n,c,t,s=0;
 printf("enter a number\n");
 scanf("%d",&n);
 t=n;
 while(n>0)
 {
  c=n%10;
  s=s+(c*c*c);
  n=n/10;
 }
 if(s==t)
 {
  printf("the number is armstrong");
 }
 else
 {
  printf("the number is not armstrong");
 }
 getch();
}
Read more

Q2)write a c programme to find solution for quadratic equation?


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
 clrscr();
 int a,b,c;
 float d,r1,r2;
 printf("enter coefficients of equation\n");
 scanf("%d %d %d",&a,&b,&c);
 if(a==0)
  {
   printf("not possible");
  }
 else
  {
   d=((b*b)-(4*a*c));
 if(d==0)
  {
    printf("roots are real and equal\n");
    r1=((-b/(2*a)));
    printf("r1=r2=%f",r1);
  }
 if(d>0)
  {
   printf("roots are real and distinct\n");
   r1=((-b+sqrt(d))/(2*a));
   r2=((-b-sqrt(d))/(2*a));
   printf("r1=%f \nr2=%f",r1,r2);
  }
 if(d<0)
  {
   printf("roots are imaginary\n");
   d=-d;
   r1=((-b)/(2*a));
   r2=((sqrt(d)/(2*a)));
   printf("r1=%f+i %f \nr2=%f-i %f",r1,r2,r1,r2);
  }
  }
getch();
}
Read more

Q1) write a program to impliment simple calculator?


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

#include<stdio.h>
#include<conio.h>
void main()
{
 clrscr();
 int a,b,c,m,ch,n;
 printf("simple calculator\n");
 do
 {
  printf("main menu");
  printf("\n 1.addition \n 2.subtraction");
  printf("\n 3.multiplication \n 4.division\n");
  printf("enter your choice\n");
  scanf("%d",&ch);
  switch(ch)
   {
    case 1:
     printf("enter 2 no\n");
     scanf("%d %d",&a,&b);
     c=a+b;
     printf("sum=%d\n",c);
     break;
    case 2:
     printf("enter 2 no\n");
     scanf("%d %d",&a,&b);
     c=a-b;
     printf("difference=%d\n",c);
     break;
    case 3:
     printf("enter 2 no\n");
     scanf("%d %d",&a,&b);
     c=a*b;
     printf("product=%d\n",c);
     break;
   case 4:
     printf("enter 2 no\n");
     scanf("%d %d",&a,&b);
     if(b==0)
     {
      printf("division not possible\n");
     }
     else
     {
      c=a/b;
      printf("quotient=%d\n",c);
     }
     break;
    default:
      printf("invalid choice\n");
   }
  printf("if you wants to continue press 1 other wise press any key\n");
  scanf("%d",&n);
 }while(n==1);
  getch();
}
Read more

LinkWithin

Related Posts Plugin for WordPress, Blogger...