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>
void 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; // 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
search_in_array(arr,size,num);//calling of function
getch();
return 0;
}
void 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
{
printf("number found and number %d location is %d\n",number,k);//printing the location
}
else
{
printf("given number is not in the list");//printing not message
}
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>
void 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; // 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
search_in_array(arr,size,num);//calling of function
return 0;
}
void 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
{
printf("number found and number %d location is %d\n",number,k);//printing the location
}
else
{
printf("given number is not in the list");//printing not message
}
getch();
}
-------------------------------------------------------------------
/*WAP to input elements and search a number in that.
Pass Weight as an array as parameter.*/
#include<stdio.h>
#include<conio.h>
void 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; // 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
search_in_array(arr,size,num);//calling of function
getch();
return 0;
}
void 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
{
printf("number found and number %d location is %d\n",number,k);//printing the location
}
else
{
printf("given number is not in the list");//printing not message
}
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>
void 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; // 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
search_in_array(arr,size,num);//calling of function
return 0;
}
void 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
{
printf("number found and number %d location is %d\n",number,k);//printing the location
}
else
{
printf("given number is not in the list");//printing not message
}
getch();
}
No comments:
Post a Comment