Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <stdio.h>
  2. int main(void)
  3. {
  4. int i=0,j,a[9];
  5.  
  6. while(a[i]!= 42)
  7. {
  8. ++i;
  9. scanf("%d",&a[i]);
  10. }
  11. for(j=0;j<i;j++)
  12. {
  13. printf("%d",a[j]);
  14. printf("n");
  15. }
  16. return 0;
  17. }
  18.  
  19. #include <stdio.h>
  20. int main(void)
  21. {
  22. int i=0,j,a[9];
  23.  
  24. scanf("%d",&a[i]);
  25. printf("%dn",a[i]);
  26.  
  27. while(a[i]!=42)
  28. {
  29. ++i;
  30. scanf("%d",&a[i]);
  31. if(a[i]!=42)
  32. printf("%dn",a[i]);
  33. }
  34. }
  35.  
  36. #include <stdio.h>
  37.  
  38. int main(void)
  39. {
  40. int i = 0;
  41. while (scanf("%dn", &i) > 0 && i != 42)
  42. {
  43. printf("%dn", i);
  44. }
  45. return 0;
  46. }
  47.  
  48. #include <stdio.h>
  49.  
  50. int main(void)
  51. {
  52. int i = 0;
  53. while (scanf("%dn", &i) > 0 && i != 42)
  54. {
  55. printf("%dn", i);
  56. }
  57. return 0;
  58. }
  59.  
  60. #include <stdio.h>
  61.  
  62. int main(void)
  63. {
  64. int i=0,j,a[9]; // this will be past the end of the array after 9 inputs
  65.  
  66. // the following 'while' loop will run forever, progressively
  67. // writing further and further past the end of the
  68. // a[] array until a seg fault occurs
  69. while(a[i]!= 42) // the a[] array contains garbage
  70. {
  71. ++i; // this 'pre-increment' results in skipping a[0]
  72. scanf("%d",&a[i]); // will fail due to no allowance for white space
  73. }
  74.  
  75. // execution will never get here
  76. for(j=0;j<i;j++) // tries to print a[0] which is not initialized
  77. {
  78. printf("%d",a[j]);
  79. printf("n");
  80. }
  81. return 0;
  82. }
  83.  
  84. #include <iostream>
  85. #include <vector>
  86. #include <iterator>
  87. using namespace std;
  88.  
  89. int main() {
  90. vector<int> v;
  91. int i=0,input;
  92. vector<int>::iterator ip;
  93. while(i!=5)
  94. {
  95. cin>>input;
  96. if(input!=42)
  97. {
  98. v.push_back(input);
  99. }
  100. else{
  101. break;
  102. }
  103. }
  104. cout<<"size of vector is: "<<v.size()
  105. ;
  106. for(ip=v.begin();ip!=v.end();ip++)
  107. cout<<*ip<<endl;
  108. return 0;
  109. }
Add Comment
Please, Sign In to add comment