Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,208,086 members, 8,001,458 topics. Date: Wednesday, 13 November 2024 at 10:53 AM

I Need Help With Pointers In C - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / I Need Help With Pointers In C (2436 Views)

Creating UWP Application In C# Or C++ (xaml) / Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD / [problem] Write A Program In C++ That Finds The Hcf Of 2 Numbers Without Using A Recursive Function (2) (3) (4)

(1) (Reply) (Go Down)

I Need Help With Pointers In C by xterra2(m): 3:03pm On Dec 21, 2011
EDIT : problem solved

Removed the code in case any of my classmate is on NL sees the code and tell my teacher I asked for help grin
Re: I Need Help With Pointers In C by Fayimora(m): 4:42pm On Dec 21, 2011
[size=13pt]What you are doing is COMPLETELY different from what you were asked to do! You were asked to find the largest btw three numbers. One way would be to use an array. Now you should have a pointer to an int(or any suitable type) array! Since you have to use a function, then you pass two values to a function that returns the largest between them.

Say you have,
10 70 40
declare a variable that would store the highest. I would call it 'highestNumberSoFar'

We pass the address of 10 and 70 to our function(that should be easy),  now we receive the addresses and then deference each of them and return the highest value! NExt we pass 70 and 40. . . . . and so on.

I intentionally did not write any bit of code. Now you have 'an algorithm', so give me an implementation.[/size]
Re: I Need Help With Pointers In C by xterra2(m): 5:22pm On Dec 21, 2011
^^ thanks for the reply
The code above was given by my teacher and he said to modify the code using pointers and function prototype to accept 3 numbers and get the highest of the 3 numbers

I can't do pointers , please help me

Please write the code
Re: I Need Help With Pointers In C by lordZOUGA(m): 12:45pm On Dec 26, 2011
uh, Don't u want a reply in C++?
Re: I Need Help With Pointers In C by Kobojunkie: 1:08am On Dec 27, 2011
#include <stdio.h>

void cubeByReference ( int *nPtr ); //prototpye

int main()
{
    int num = 5;
    int *p = &num;
      printf("The original value of the number is %d", num);

    //Pass adress of number to cubeByReference
    cubeByReference (p);

    printf("\n The new value of number is %d\n", num );
    return 0;
} // end main


// calculate cuve of *nPtr; modifies number in main
void cubeByReference (int *nPtr )
{
    *nPtr = *nPtr * *nPtr * *nPtr;
}

(1) (Reply)

Apple Buys Hopstop.com From Nigerian Entrepreneur Chinedu Echeruo For $1 Billion / Great Websites For Developers / Php Patterns

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.