Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

why my code is not working?

+6 votes
asked Apr 10, 2021 by Tarun Kumar Tarlana (350 points)
int main()
 {
     int x,y,z;

     int n ;

       printf("enter x,y,z of cuboid ");
       scanf("%d %d %d",&x,&y,&z);
       printf(" enter n");
       scanf(" %d ",&n);

        for(int i=0;i<x;i++)
        { printf("%d",i);
            for(int j=0;j<y;j++)
            {
                for(int k=0;k<z;k++)
                {
                    if (i+j+k ==n)
                    {
                        printf("(%d %d %d)",i,j,k);

                    }
                }
            }
        }
     return 0;
 }

4 Answers

+1 vote
answered Apr 11, 2021 by U S (230 points)
Kindly specify what are you trying to find from this program. Use #include<stdio.h> in the very beginning to make the code run.
+2 votes
answered Apr 12, 2021 by Peter Minarik (84,720 points)

Look at your scanf functions. They contain "random" space characters in the formatting string. This makes scanf try to read whitespace characters from the input effectively making your entered input invalid.

To make your input work correctly, remove these white-space characters from scanf:

printf("enter x,y,z of cuboid ");
scanf("%d%d%d", &x, &y, &z);
printf(" enter n");
scanf("%d",&n);
+2 votes
answered Apr 14, 2021 by Nitesh patel (180 points)
There is an extra line
Which is  printf("%d",i);
This is not required.
And also there is not most required line
Which is releTed to #include<studio.h>
+2 votes
answered Apr 14, 2021 by Arun Personal Account (220 points)

This program will work specified input only not for all format of input.

Add a header file : #include<stdio.h>

Try this input : x,y,z = 3,2,1.   and n=6

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...