Pages

Sunday 29 April 2012

arrays


A program to calculate no of 10, 50 100 notes
#include<stdio.h>
#include<conio.h>
void add(int *a);
main()
{
      int value,x,y,z,a,b,c;
      scanf("%d",&value);
      a=value/100;
      printf("no of 100th %d",a);
      x=value%100;
      b=x/50;
      printf("\n no of fiftys %d",b);
      z=value-(a*100)-(b*50);
      c=z/10;
      printf("no of 10th %d",c);
      getch();
      }


(a) Write a function to calculate the factorial value of any integer entered through the keyboard.
(b) Write a function power ( a, b ), to calculate the value of a raised to b.
#include<stdio.h>
#include<conio.h> 
int power(int a,int b);
main()
{
      int a,b,f;
      scanf("%d",&b);
      scanf("%d",&a);
      f=power(a,b);
      printf("%d",f);
      getch();
      }
int  power(int a,int b)
      {
               int c,lov=1;
         for(c=1;c<=b;c++)
         {lov=lov*a;}
         return lov;
                 }
(c) Write a general-purpose function to convert any given year into its roman equivalent. The following table shows the roman equivalents of decimal numbers:
Example:
Roman equivalent of 1988 is mdcccclxxxviii
Roman equivalent of 1525 is mdxxv
(d) Any year is entered through the keyboard. Write a function to determine whether the year is a leap year or not.
(e) A positive integer is entered through the keyboard. Write a function to obtain the prime factors of this number


Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In a Fibonacci sequence the sum of two successive terms gives the third term. Following are the first few terms of the Fibonacci sequence: 1 1 2 3 5 8 13 21 34 55 89...



#include<stdio.h>
#include<conio.h> 
int power(int n);
main()
{
      int a=0,b=1,n;
      scanf("%d",&n);
      power(n);
      getch();
      }
int  power(int n)
      {
               int c,a=0,b=1;
      printf("%d",b);
      printf("%d",a);
         for(c=0;c<=n;c++)
         {c=a+b;
         printf("%d",c);
         a=b;
         b=c;
                 }
}




Write a program to pick up the largest number from any 5 row by 5 column matrix.


#include<stdio.h>
#include<conio.h>
main( )
{
      int a
      [3][3],i,j,b;
      for(i=0;i<=2;i++)
      for(j=0;j<=2;j++)
      scanf("%d",&a[i][j]);
      b=a[0][0];
      for(i=0;i<=2;i++)
      for(j=0;j<=2;j++)
      {
                       if(b<a[i][j])
                       b=a[i][j];}
                       printf("%d",b);
      getch();
      }


Write a program to obtain transpose of a 4 x 4 matrix. The transpose of a matrix is obtained by exchanging the elements of each row with the elements of the corresponding column

#include<stdio.h>
#include<conio.h>
main( )
{
      int a
      [3][3],i,j,b;
      for(i=0;i<=2;i++)
      for(j=0;j<=2;j++)
      scanf("%d",&a[i][j]);
      for(j=0;j<=2;j++)
      {
      for(i=0;i<=2;i++)
      {
                       printf("\t%d",a[i][j]);}
                       printf("\n");}
      getch();
      }        



Write a program to add two 6 x 6 matrices.
# include<stdio.h>
# include<conio.h>
main()
{
int a[3][3],b[3][3],c[3][3],i,j;
printf("Enter the elements of a matrix");
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
scanf("%d",&a[i][j]);
printf("elements of 2nd matrix are\n");
for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

scanf("%d",&b[i][j]);
printf("sum of two materices are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}
(2) Write a program to multiply any two 3 x 3 matrices.
# include<stdio.h>
# include<conio.h>
main()
{
int a[3][3],b[3][3],c[3][3],i,j,k,sum=0;
printf("Enter the elements of a matrix");
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
scanf("%d",&a[i][j]);
printf("Enter the second matrix\n");
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
scanf("%d",&b[i][j]);
printf("Multiplication of materix are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
                 c[i][j]=0;
for(k=0;k<=2;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}
(3) Write a program to sort all the elements of a 4 x 4 matrix.

(4) Write a program to obtain the determinant value of a 5 x 5 matrix.
        

arrays

1Q.      Twenty-five numbers are entered from the keyboard into an array. The number to be searched     is entered through the keyboard by the user. Write a program to find if the number to be searched is present in the array and if it is present, display the number of times it appears in the array.
           #include<stdio.h>
#include<conio.h>
main()
{
      int i;
      int z=0;
      int teja[25]={1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,12,13,14,16,11};
      int search;
      printf("enter letter to search");
      scanf("%d",&search);
      for(i=0;i<=24;i++)
      if(search==teja[i])
      {
                         printf("the number being repeated%d\n",search);
                         z=z+1;
                         }
                         printf("\nno of times%d",z);
      getch();
}



Twenty-five numbers are entered from the keyboard into an array. Write a program to find out how many of them are positive, how many are negative, how many are even and how many odd.
           #include<stdio.h>
#include<conio.h>
main()
{
      int i;
      int z=0,x=0;
      int teja[25]={1,2,3,4,5,6,7,8,9,-1,-2,-3,-4,-5,-6,-7,-8,-9,10,-10,1,2,3,4,5};
      for(i=0;i<=24;i++)
      if(teja[i]>0)
      z=z+1;
                         printf("\n no of positive nos%d",z);
      for(i=0;i<=24;i++)
      if(teja[i]<0)
      x=x+1;
                         printf("\n no of negitive nos%d",x);
      getch();
      }