C++ not getting the output,What is wrong?

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

  • vinci
    vinci
    what is the purpose of the above program?i think array declaration has some syntax problems
  • KenJackson
    KenJackson
    I had to change to 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< 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 
    using namespace std;
    // ...
    
    [/noparse]
  • Gandalf
    Gandalf
    ayushk1
    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


    #include
    //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];
    cout< }
    }
    return 0;
    }

    one basic mistake is the brackets for this for loop

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

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

    it gives output

    111155559999hey i am sure u can rectify yourself ....

You are reading an archived discussion.

Related Posts

It looks like the technology bloggers are creating a buzz about the WiFi Direct Technology and its potential to replace the Bluetooth Technology. With WiFi direct, file sharing and streaming...
The 20th Question of the CE Grand Quiz Contest is as follows - [Worth 20 CE Coins] Who said this - "F V Z C Y V P V G...
I want 'Countdown Timer' code for my project, and my project is about 'Online Examination'. So please get me that code so that i can complete my project as soon...
Can anyone explain me,which logic gates follow and don't follow which of the laws like Commutative,Distributive,Associative etc. And how?
1) If z=x*y then z*x is? Options- 1)x 2)0 3)y 4)1 2) How many functions are possible with 'n' binary variables? 3) How many functions are possible with 2 Boolean...