Click here to Skip to main content
15,560,678 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
* Write a program for working with a table of dimensions rkk, where r = 7, c = 5.
* Generate table elements, etc. The numbers from [a, b) are randomly selected,
* where a and b are entered by the user. Make sure that a < b.
* Determine the sum of the columns of the table, place it in a row and display it on std.
* Reduce the minimum rows of the table, place them in a row and display them on std.
* Determine the maximum element on the main diagonal and display it on std.
* Swap places in the third and penultimate column of the table and display the result
* on std.

What I have tried:

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#define r 7
#define k 5

void mySwap(int* x, int* y) {
int temp = *x;
*x = *y;
y = temp;
}

int minString(int string, int n) {
int i = 0, min = string[0];
for (i = 0; i < n; i++) {
if (min > string[i]) {
min = string[i];
}
}
return min;
}

int main()
{
int a = 0, b = 0;

printf("Enter a: ");
scanf("%d", &a);
printf("Enter b: ");
scanf("%d", &b);
if (a > b) {
mySwap(&a, &b);
}
else if (a == b) {
b++;
}

int table[r][c], sum[r]={0}, i=0, j=0;

for(i=0;i
Posted
Updated 11-Apr-21 13:01pm
Comments
OriginalGriff 11-Apr-21 16:07pm    
And?
What does it do that you didn't expect, or not do that you did?
What have you done to find out why?
What did the debugger show you?

Where are you stuck?
What help do you need?
Code Code 2021 11-Apr-21 16:17pm    
There is no solution. Don't work I tried everything.
OriginalGriff 11-Apr-21 16:23pm    
If you "tried everything" the you should probably give up development.

If on the other hand you mean "I looked at it and nothing leapt out at me" then I'd suggest you google for "what does a debugger do?" and see if it can help you ...
Code Code 2021 11-Apr-21 16:31pm    
Ok I found error it's working now.
Rick York 11-Apr-21 16:16pm    
I would guess your variables r and k are rows and columns. That's a problem : one should not have to guess. Single letter definitions like that are a really bad idea. Spell them out : ROWS and COLUMNS or something similar. You declared your table with c columns, not k, so what you have posted will not compile.

1 solution

Quote:
Ok I found error it's working now.

Nice to ear you found the solution.
First of all, part of your code is missing in the question, it makes it difficult to help you.
-----
To get some help, it is a good idea to describe how your code don't do what you expect.

As programmer, your job is also to check that your code work as expected, and if it don't, your job is to correct bugs as much as possible.
Fortunately, tools have been built, the main tool is the debugger.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

1.11 — Debugging your program (stepping and breakpoints) | Learn C++[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900