Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(void)
- {
- int i=0,j,a[9];
- while(a[i]!= 42)
- {
- ++i;
- scanf("%d",&a[i]);
- }
- for(j=0;j<i;j++)
- {
- printf("%d",a[j]);
- printf("n");
- }
- return 0;
- }
- #include <stdio.h>
- int main(void)
- {
- int i=0,j,a[9];
- scanf("%d",&a[i]);
- printf("%dn",a[i]);
- while(a[i]!=42)
- {
- ++i;
- scanf("%d",&a[i]);
- if(a[i]!=42)
- printf("%dn",a[i]);
- }
- }
- #include <stdio.h>
- int main(void)
- {
- int i = 0;
- while (scanf("%dn", &i) > 0 && i != 42)
- {
- printf("%dn", i);
- }
- return 0;
- }
- #include <stdio.h>
- int main(void)
- {
- int i = 0;
- while (scanf("%dn", &i) > 0 && i != 42)
- {
- printf("%dn", i);
- }
- return 0;
- }
- #include <stdio.h>
- int main(void)
- {
- int i=0,j,a[9]; // this will be past the end of the array after 9 inputs
- // the following 'while' loop will run forever, progressively
- // writing further and further past the end of the
- // a[] array until a seg fault occurs
- while(a[i]!= 42) // the a[] array contains garbage
- {
- ++i; // this 'pre-increment' results in skipping a[0]
- scanf("%d",&a[i]); // will fail due to no allowance for white space
- }
- // execution will never get here
- for(j=0;j<i;j++) // tries to print a[0] which is not initialized
- {
- printf("%d",a[j]);
- printf("n");
- }
- return 0;
- }
- #include <iostream>
- #include <vector>
- #include <iterator>
- using namespace std;
- int main() {
- vector<int> v;
- int i=0,input;
- vector<int>::iterator ip;
- while(i!=5)
- {
- cin>>input;
- if(input!=42)
- {
- v.push_back(input);
- }
- else{
- break;
- }
- }
- cout<<"size of vector is: "<<v.size()
- ;
- for(ip=v.begin();ip!=v.end();ip++)
- cout<<*ip<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment