Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6. int arr1[100];
  7. int arr2[100];
  8. int i;
  9. int n;
  10. int search;
  11. int found;
  12. char resposta [4];
  13.  
  14. printf("\nHow many numbers will you put in the array?");
  15. scanf("%d", &n);
  16.  
  17. for (i=0; i<=n; i++){
  18. printf("Element - %d : ",i);
  19. scanf("%d", &arr1[i]);
  20. }
  21.  
  22.  
  23. printf("The elements stored in the first array are: \n"); //print the first array
  24.  
  25. for (i=0; i<=n; i++){
  26. printf("%d\n", arr1[i]);
  27. }
  28.  
  29.  
  30. for (i=0; i<=n; i++){ //copy the first array to the second one
  31. arr2[i] = arr1[i];
  32. }
  33.  
  34. printf("The elements stored in the second array are: \n "); // print the second array
  35.  
  36. for (i=0; i<=n; i++){
  37. printf("%d\n", arr2[i]);
  38. }
  39.  
  40. printf("\Do you want to search for anything? (yes or no)"); /*procura de um numero*/
  41. scanf("%s",&resposta);
  42.  
  43. if (strcmp(resposta,"yes")==0){
  44.  
  45. printf("\nInsert the element that you want to search!\n");
  46. scanf("%d", &search);
  47.  
  48. found = 0;
  49.  
  50. for (i=0; i<=n; i++){
  51. if (arr2[i] == search){
  52. found = 1;
  53. break;
  54. }
  55. }
  56.  
  57.  
  58. if (found == 1){
  59. printf("\n%d was found at position %d\n", search, i+1);
  60. }
  61. else printf("\n%d was not found in the array\n", search);
  62. }
  63. else return;
  64.  
  65.  
  66.  
  67.  
  68.  
  69. system ("pause");
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement