-->

WAP to search a number in a list of numbers using array as a parameter.

in turboc++
-----------------------------------------------------------------------------------------
/*WAP to input elements and search a number in that.
Pass Weight as an array as parameter.*/
#include<stdio.h>
#include<conio.h>
int search_in_array(float array[200],int size,int number);//prototype with array and size and number parameters
int main()
{

float arr[200];int k,num;            // array declaration with maximum limit 200
int size,f;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
printf("enter elements\n");
for(k=0;k<size;k++)//loop execution
{
   scanf("%f",&arr[k]);//data inputs
}
printf("enter number to be searched\n");
scanf("%d",&num);                //number input to be searched
f=search_in_array(arr,size,num);//assigning return value to variable f
if(f==0)                        //testing the value
{
printf("number not found \n");//calling of function
}
else
{
    printf("number found and lcoation=%d",f);
}
getch();
return 0;
}
int search_in_array(float array[200],int size,int number)//body line
{

int k;//declaration
int found;

for(k=0;k<size;k++)//loop execution

{
 if(number==array[k])
        {
            found=0; //assigning 0 on its finding
            break;
        }
        else
        {
            found=1;//else assigning 1
        }
}
if(found==0)//testing the condition
{
    return k;//returning the location
}
    else
{
        return 0;//returning nothing
}
    getch();
}






--------------------------------------------------------------------------------------------
in codeblocks:
--------------------------------------------------------------------------------------------------------------
/*WAP to input elements and search a number in that.
Pass Weight as an array as parameter.*/
#include<stdio.h>
#include<conio.h>
int search_in_array(float array[200],int size,int number);//prototype with array and size and number parameters
int main()
{

float arr[200];int k,num;            // array declaration with maximum limit 200
int size,f;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
printf("enter elements\n");
for(k=0;k<size;k++)//loop execution
{
   scanf("%f",&arr[k]);//data inputs
}
printf("enter number to be searched\n");
scanf("%d",&num);                //number input to be searched
f=search_in_array(arr,size,num);//assigning return value to variable f
if(f==0)                        //testing the value
{
printf("number not found \n");//calling of function
}
else
{
    printf("number found and lcoation=%d",f);
}
getch();
return 0;
}
int search_in_array(float array[200],int size,int number)//body line
{

int k;//declaration
int found;

for(k=0;k<size;k++)//loop execution

{
 if(number==array[k])
        {
            found=0; //assigning 0 on its finding
            break;
        }
        else
        {
            found=1;//else assigning 1
        }
}
if(found==0)//testing the condition
{
    return k;//returning k value
}
    else
{
        return 0;//returning nothing
}
    getch();
}

WAP to input weight of 100 students and count number of students who have weight in between 40 and 60 kg. Pass Weight as an array as parameter.

in truboc++
-----------------------------------------------------------------------------------------

/*WAP to input weight of 100 students and count number of students who have weight in between 40 and 60 kg.
Pass Weight as an array as parameter.*/
#include<stdio.h>
#include<conio.h>
int total_nu_of_array(float array[200],int size);//prototype with array and size parameters
int main()
{

float arr[200];int k;            // array declaration with maximum limit 200
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
printf("enter weights of students\n");
for(k=0;k<size;k++)//loop execution
{
   scanf("%f",&arr[k]);//data/weight inputs
}
printf("total in given range=%d",total_nu_of_array(arr,size));//calling of function
getch();
return 0;
}

int total_nu_of_array(float array[200],int size)//body line
{

int k;//declaration
int count=0;

for(k=0;k<size;k++)//loop execution

{
if(array[k]>40 && array[k]<60)//condition testing
    {
        count++;//counting if the condition is true
    }
}

return count;//returning total count

getch();

}






---------------------------------------------------------------------------------------------------------
in codeblocks:
----------------------------------------------------------------------------------------------------------
/*WAP to input weight of 100 students and count number of students who have weight in between 40 and 60 kg.
Pass Weight as an array as parameter.*/
#include<stdio.h>
#include<conio.h>
int total_nu_of_array(float array[200],int size);//prototype with array and size parameters
int main()
{

float arr[200];int k;            // array declaration with maximum limit 200
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
printf("enter weights of students\n");
for(k=0;k<size;k++)//loop execution
{
   scanf("%f",&arr[k]);//data/weight inputs
}
printf("total in given range=%d",total_nu_of_array(arr,size));//calling of function
getch();
return 0;
}

int total_nu_of_array(float array[200],int size)//body line
{

int k;//declaration
int count=0;

for(k=0;k<size;k++)//loop execution

{
if(array[k]>40 && array[k]<60)//condition testing
    {
        count++;//counting if the condition is true
    }
}

return count;//returning total count

getch();

}

WAp to find greatest number among ten numbers. PAss array as parameter.

in turboc++
----------------------------------------------------------------------------------------------------------

//WAp to find greatest number among ten or more numbers. PAss array as parameter. and it returns some value.
#include<stdio.h>
#include<conio.h>
float max_of_array(float array[5],int size);//prototype with array and size parameters
int main()
{

float arr[100];int k;            // array declaration with maximum limit 100
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
for(k=0;k<size;k++)//loop execution

{
   printf("enter element for location=%d\n",k); // for elements in particular location
   scanf("%f",&arr[k]);//data inputs
}
printf("maximum value=%f",max_of_array(arr,size));//calling of function
getch();
return 0;
}

float max_of_array(float array[5],int size)//body line
{

int k;//declaration
int max;
max=array[0];//assigning first value to max.

for(k=0;k<size;k++)//loop execution

{
if(max<array[k])//condition testing
    {
        max=array[k];//assigning value if the condition is true
    }
}

return max;//returning maxmimum element

getch();

}









----------------------------------------------------------------------------------------------------------------------
in codeblocks:
----------------------------------------------------------------------------------------------------------------------
//WAp to find greatest number among ten or more numbers. PAss array as parameter. and it returns some value.
#include<stdio.h>
#include<conio.h>
float max_of_array(float array[5],int size);//prototype with array and size parameters
int main()
{

float arr[100];int k;            // array declaration with maximum limit 100
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
for(k=0;k<size;k++)//loop execution

{
   printf("enter element for location=%d\n",k); // for elements in particular location
   scanf("%f",&arr[k]);//data inputs
}
printf("maximum value=%f",max_of_array(arr,size));//calling of function
return 0;
}

float max_of_array(float array[5],int size)//body line
{

int k;//declaration
int max;
max=array[0];//assigning first value to max.

for(k=0;k<size;k++)//loop execution

{
if(max<array[k])//condition testing
    {
        max=array[k];//assigning value if the condition is true
    }
}

return max;//returning maxmimum element

getch();

}


wap to get length of string by passing string as parameter.

in turboc++
-----------------------------------------------------------------------------------------------------
//wap to get length of string by passing string as parameter.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int stringlength(char array[40]);//prototype with array string; we can also use simply array[]
int main()
{
char arr[20];            // array declaration with maximum limit 20
                     
printf("enter string\n");
gets(arr);//gets string

printf("the length=%d",stringlength(arr));//calling of function with argument
getch();
return 0;
}
int stringlength(char array[40])//body line
{
return strlen(array);
getch();
}

---------------------------------------------------------------------------------------------------------
in codeblocks:
----------------------------------------------------------------------------------------------------------
//wap to get length of string by passing string as parameter.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int stringlength(char array[40]);//prototype with array string; we can also use simply array[]
int main()
{
char arr[20];            // array declaration with maximum limit 20
                       
printf("enter string\n");
gets(arr);//gets string

printf("the length=%d",stringlength(arr));//calling of function with argument
return 0;
}
int stringlength(char array[40])//body line
{
return strlen(array);
getch();
}

WAP to pass array as parameter to input any five numbers and then find their sum.

in turboc++
-----------------------------------------------------------------------------------------
//program to enter any five elements and find their sum.
#include<stdio.h>
#include<conio.h>
int sum_of_array(float array[5],int size);//prototype with array and size parameters
int main()
{
float arr[20];int k;            // array declaration with maximum limit 20
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
for(k=0;k<size;k++)//loop execution
{
   printf("enter element for location=%d\n",k); // for elements in particular location
   scanf("%f",&arr[k]);//data inputs
}
printf("the sum=%d",sum_of_array(arr,size));//calling of function
getch();
return 0;
}
int sum_of_array(float array[5],int size)//body line
{
int k;float s=0;//declaration
for(k=0;k<size;k++)//loop execution
{
   s=s+array[k];//finding sum
}
return s;//returning sum(s)
getch();
}
------------------------------------------------------------------------------------------------------------
in codeblocks:
------------------------------------------------------------------------------------------------------------
//program to enter any five elements and find their sum.
#include<stdio.h>
#include<conio.h>
int sum_of_array(float array[5],int size);//prototype with array and size parameters
int main()
{
float arr[20];int k;            // array declaration with maximum limit 20
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
for(k=0;k<size;k++)//loop execution
{
   printf("enter element for location=%d\n",k); // for elements in particular location
   scanf("%f",&arr[k]);//data inputs
}
printf("the sum=%d",sum_of_array(arr,size));//calling of function
return 0;
}
int sum_of_array(float array[5],int size)//body line
{
int k;float s=0;//declaration
for(k=0;k<size;k++)//loop execution
{
   s=s+array[k];//finding sum
}
return s;//returning sum(s)
getch();
}

WAP to find sum of two matrices. Here pass matrix as parameter.

in turboc++
-------------------------------------------------------------------------------------------------------
//WAP to find sum of two matrices of order mxn. Here pass matrix as parameter.
#include<stdio.h>
#include<conio.h>
void sum_of_matrix(int matrix[100][100],int matrix1[100][100],int row,int col);//function prototype
int main()
{
int mat1[100][100],mat2[100][100];              //matrix declaration of max size 100x100
int i,j;
int total_row,total_col;             //declaration of variable
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of first matrix mat1\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&mat1[i][j]);   // getting inputs from user
        }
}
printf("enter elements of second matrix mat2\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&mat2[i][j]);   // getting inputs from user
        }
}

sum_of_matrix(mat1,mat2,total_row,total_col);//function calling
getch();

return 0;
}

void sum_of_matrix(int matrix[100][100],int matrix1[100][100],int row,int col)
{
    int i,j;
printf("sum of two matrices are\n");
for(i=0;i<row;i++)
{
  for(j=0;j<col;j++)           
       {
           printf(" %d ",matrix[i][j]+matrix1[i][j]); // sum and display of matrix
        }
        printf("\n");                    // display in next row
}
getch();
}

WAp to find transpose of a matrix. Here , pass matrix as parameter.

in turboc++
--------------------------------------------------------------------------------------------------------
//WAP to transpose  a matrix/array of order mxn.
#include<stdio.h>
#include<conio.h>
void tran_matrix(int array[100][100],int row,int col);//fucntion prototype
int main()
{
int matrics_1[100][100];              //matrix declaration of max size 100x100
int i,j;
int total_row,total_col;             //declaration of variable
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
tran_matrix(matrics_1,total_row,total_col);//function calling
getch();
return 0;
}

void tran_matrix(int array[100][100],int row,int col)
{
    int i,j;
printf("before transpose\n");             // message display
for(i=0;i<row;i++)
{
  for(j=0;j<col;j++)           
       {
           printf(" %d ",array[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("after transpose\n");             // for transposed matrix
for(i=0;i<col;i++)
{
  for(j=0;j<row;j++)
       {
        printf(" %d ",array[j][i]);    // display of matrix with trasnposed elemnts
       }
       printf("\n");
}   
getch();
}
-------------------------------------------------------------------------------------------
in codeblocks:-
-----------------------------------------------------------------------------------------------------
//WAP to transpose  a matrix/array of order mxn.
#include<stdio.h>
#include<conio.h>
void tran_matrix(int array[100][100],int row,int col);//fucntion prototype
int main()
{
int matrics_1[100][100];              //matrix declaration of max size 100x100
int i,j;
int total_row,total_col;             //declaration of variable
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
tran_matrix(matrics_1,total_row,total_col);//function calling
return 0;
}

void tran_matrix(int array[100][100],int row,int col)
{
    int i,j;
printf("before transpose\n");             // message display
for(i=0;i<row;i++)
{
  for(j=0;j<col;j++)           
       {
           printf(" %d ",array[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("after transpose\n");             // for transposed matrix
for(i=0;i<col;i++)
{
  for(j=0;j<row;j++)
       {
        printf(" %d ",array[j][i]);    // display of matrix with trasnposed elemnts
       }
       printf("\n");
}   
getch();
}