LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-23-2004, 10:11 PM   #1
ripwheels8
LQ Newbie
 
Registered: Jul 2004
Posts: 9

Rep: Reputation: 0
Post Homework question, My code posted.


This is the question:

Write a C program to reverse the digits of a positive integer number. For example, if the number 8735 is entered, the number displayed should be 5378. (Hint: Use a do statement and continuously strip off and display the units digit of the number. If the variable num initially contains the number entered, the units digit is obtained as (num % 10). After a units digit is displayed, dividing the number by 10 sets up the number for the next iteration. Thus, (8735 % 10) is 5 and (8735 / 10) is 873. The do statement should continue as long as the remaining number is not zero).

This is my code:

void findmax(int val[10][20])
{
int i, j, max;
max = 0;
for(i = 0; i < 10; ++i)
for(j = 0; j < 20; ++j)
if (val[i][j] > max)
max = val[i][j];
printf("\nThe maximum array value is %d\n", max);

return;

}

These are the compiler errors I receive:
Error E2268 <filename> 10: Call to undefined function 'printf' in function findmax(int (*)[20])

Please help. I have looked through everything I have and can't figure it out. Also, How would you display the row and column number of the element w/ the max value?
 
Old 07-24-2004, 12:25 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Perhaps are you missing an include file.
You also seem to have overlook the hints given ...
 
Old 07-24-2004, 12:41 AM   #3
ripwheels8
LQ Newbie
 
Registered: Jul 2004
Posts: 9

Original Poster
Rep: Reputation: 0
Or I posted the wrong question for the code I had since I am an idiot. Here is the question for the code I have posted above:
Write a function that finds and displays the maximum value in a two-dimensional array of integers. The array should be declared as a 10-by-20 array of integers in main().


The code I have:
This is my code:

void findmax(int val[10][20])
{
int i, j, max;
max = 0;
for(i = 0; i < 10; ++i)
for(j = 0; j < 20; ++j)
if (val[i][j] > max)
max = val[i][j];
printf("\nThe maximum array value is %d\n", max);

return;

}

Also wondering how to display the row and column number of the element w/ the max value. Thanks for putting up with my stupidity.
Mike
 
Old 07-24-2004, 01:02 AM   #4
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
Hi ripwheels8,
The compilation syntax error you have is because you need to add the line
Code:
#include <stdio.h>
in the top of your source code. The compiler needs to know the prototype of the function "printf", which is declared in "/usr/include/stdio.h".
Besides this, reading the source of your function, we can see that it is a routine to find a maximum value in the array it receives as parameter. There is nothing to do with your home work.
To display the row and column of your array in the function you post, you need to already save the values of the indexes you are using when you get the maximum values. So, instead of
Code:
if (val[i][j] > max)
  max = val[i][j]
you have to
Code:
if (val[i][j] > max) {
  max = val[i][j];
  max_i = i;
  max_j = j;
}
Then when you print the result you will have these values safe. Of course, you have to declare the variable max_i and max_j on the top of the function. Two more considerations: when you submit code, use the vBcode this site has. Its hard to examine a code as an edited text. You can read about vBcode in this site faq. That was the first consideration. The second is: read carefully the problem you are submitted to until you understand before start writing some code.
I hope this helps you. Have a nice week end!
 
Old 07-24-2004, 01:25 AM   #5
ripwheels8
LQ Newbie
 
Registered: Jul 2004
Posts: 9

Original Poster
Rep: Reputation: 0
Thank you!! Hope you have a pleasant weekend as well.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
please help my homework again donotexpert Programming 7 08-23-2005 10:26 AM
help me(my homework) please! donotexpert Programming 4 08-20-2005 06:26 AM
Not getting response for question posted so.... l0f33t Linux - General 4 09-03-2003 08:01 AM
Stumpt on a homework question klfreese General 7 08-23-2003 07:51 AM
Important Partitioning Question (also posted in Installation forum). Please HELP! Soulstice Linux - Newbie 12 07-14-2001 03:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration