Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int arr1[100];
- int arr2[100];
- int i;
- int n;
- int search;
- int found;
- char resposta [4];
- printf("\nHow many numbers will you put in the array?");
- scanf("%d", &n);
- for (i=0; i<=n; i++){
- printf("Element - %d : ",i);
- scanf("%d", &arr1[i]);
- }
- printf("The elements stored in the first array are: \n"); //print the first array
- for (i=0; i<=n; i++){
- printf("%d\n", arr1[i]);
- }
- for (i=0; i<=n; i++){ //copy the first array to the second one
- arr2[i] = arr1[i];
- }
- printf("The elements stored in the second array are: \n "); // print the second array
- for (i=0; i<=n; i++){
- printf("%d\n", arr2[i]);
- }
- printf("\Do you want to search for anything? (yes or no)"); /*procura de um numero*/
- scanf("%s",&resposta);
- if (strcmp(resposta,"yes")==0){
- printf("\nInsert the element that you want to search!\n");
- scanf("%d", &search);
- found = 0;
- for (i=0; i<=n; i++){
- if (arr2[i] == search){
- found = 1;
- break;
- }
- }
- if (found == 1){
- printf("\n%d was found at position %d\n", search, i+1);
- }
- else printf("\n%d was not found in the array\n", search);
- }
- else return;
- system ("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement