CrazyEngineers
  • Hey all,
    Here is a C++ program which is as follows

    "

    #include
    int z[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};
    void main()
    {
    int a,b,c;
    for(a=0;a<3;++a) {
    c=999;
    for(b=0;b<4;++b)
    if(z[a];
    cout< }
    }

    "

    When I compile it,it doesn't show any errors,
    but the program still doesn't run.It initializes and stops in between.

    Can someone correct the program and tell me the output.

    Also,here is an interesting question-

    "A two dimensional array of size 4x4 has three different possible values.The values of the array could be 0,1 or 2.These values are input from the user via keyboard.Display the matrix.For all the values of 2 in the array,determine whether in the adjacent diagonal(either top or bottom and either left or right) whether any 1 is present.If so,display the position of such 1s corresponding to various 2s."

    I'm having a hard time finding the answer,can somone plz help me out?

    Thanks
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • vinci

    MemberNov 20, 2011

    what is the purpose of the above program?i think array declaration has some syntax problems
    Are you sure? This action cannot be undone.
    Cancel
  • KenJackson

    MemberNov 25, 2011

    I had to change <iostream.h> to <iostream> to even get it to compile.

    Next, it couldn't find cout. So either use std::cout or add the following statement after the include:
    using namespace std;

    The output is all jammed together. Try changing cout<<c; to cout << c << " ";
    And I would add cout << endl; at the end so the prompt returns correctly.

    Finally, the initialization of z[][] seems to work, though it's by happenstance. This would be more correct:
    int z[3][4] = { { 1,2,3,4 }, { 5,6,7,8 }, { 9,10,11,12 } };
    BTW, you should always use code tags when posting a code excerpt, like I did in the line above. For example:
    [noparse]
    #include <iostream>
    using namespace std;
    // ...
    
    [/noparse]
    Are you sure? This action cannot be undone.
    Cancel
  • Gandalf

    MemberNov 29, 2011

    ayushk1
    Hey all,
    Here is a C++ program which is as follows

    "

    #include<iostream.h>
    int z[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};
    void main()
    {
    int a,b,c;
    for(a=0;a<3;++a) {
    c=999;
    for(b=0;b<4;++b)
    if(z[a]<c)c=z[a];
    cout<<c;
    }
    }

    "

    When I compile it,it doesn't show any errors,
    but the program still doesn't run.It initializes and stops in between.

    Can someone correct the program and tell me the output.

    Also,here is an interesting question-

    "A two dimensional array of size 4x4 has three different possible values.The values of the array could be 0,1 or 2.These values are input from the user via keyboard.Display the matrix.For all the values of 2 in the array,determine whether in the adjacent diagonal(either top or bottom and either left or right) whether any 1 is present.If so,display the position of such 1s corresponding to various 2s."

    I'm having a hard time finding the answer,can somone plz help me out?

    Thanks


    #include<iostream.h>
    //int z[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}}
    int main()
    {
    int z[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
    int a,b,c;
    for(a=0;a<3;++a)
    {
    c=999;
    for(b=0;b<4;++b)
    {
    if(z[a]<c)c=z[a];
    cout<<c;
    }
    }
    return 0;
    }

    one basic mistake is the brackets for this for loop

    for(b=0;b<4;++b)
    {
    if(z[a]<c)c=z[a];
    cout<<c;
    }

    i used a online compiler to run it
    #-Link-Snipped-#

    it gives output

    111155559999hey i am sure u can rectify yourself ....
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register