Searching at Array with C++
A short script of basic C++ program.
I've tried to make a short script with C++ programming language, that purposed to search a value of array datas. And the program was worked succesfully.
This is my script :
#include stdio.h;
#include conio.h;
void main(){
int i; //index of array
int key; //key number to search
int array[10] = {1,2,3,4,5,6,7,8,9,10}; //definition of array
printf("please input your value here : ");
scanf("%i", &key);
int flag=0; // flag set to 0ff
// flag is to set the truth value of input
for(i=0; i<10; i++) {
if (array[i] == key)
{
flag = 1;
break;
}
}
if (flag) //if flag is true = 1
{
printf("the data input is valid");
printf("he location of data at index %i", i);
}
else
{
printf("the data input is out of range");
}
getch();
}
Note : May be this script was'nt perfect yet.. :)
Read more
A short script of basic C++ program.
I've tried to make a short script with C++ programming language, that purposed to search a value of array datas. And the program was worked succesfully.
This is my script :
#include stdio.h;
#include conio.h;
void main(){
int i; //index of array
int key; //key number to search
int array[10] = {1,2,3,4,5,6,7,8,9,10}; //definition of array
printf("please input your value here : ");
scanf("%i", &key);
int flag=0; // flag set to 0ff
// flag is to set the truth value of input
for(i=0; i<10; i++) {
if (array[i] == key)
{
flag = 1;
break;
}
}
if (flag) //if flag is true = 1
{
printf("the data input is valid");
printf("he location of data at index %i", i);
}
else
{
printf("the data input is out of range");
}
getch();
}
Note : May be this script was'nt perfect yet.. :)