[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

Really simple question !


I need a very simple program. I am just starting to learn C by myself and I have no book. If you know a good book, let me know.
I want to know how to do the following program :
(example of passing parameters to a function)

-Ask the user to input 4 real numbers at the command prompt
-send the numbers to a function to perform the follwoing
 value=(a+b squared) + (c+d)squared)

and return the value to the main program and print result.
I need a wroking program please. I want to cut and paste. Thanks
  • 2
1 Solution
I won't do questions for you (EE has strict rules about doing "homework" problems).

I can point out good books:
Illustrating C by Donald Alcock ISBN 0521468213 - this is a great book for beginners.

The C language by Ritchie and Kernighan - de facto C book...its great (tho it might be a bit outdated). its treatment of pointers and arrays is fabulous.
haielAuthor Commented:
Who said this is a homeworke assignment. I am 42 years my friend.If I have a book I am sure this can be found as exaple oe something.Anyway thanks.
Since you are just starting C programming, I didn't use anything too complicated like arrays.  Here's a program that does what you asked for.

#include <stdio.h>

double calc(double,double,double,double);

void main(void) {
        double a,b,c,d;         /** Input numbers **/
        double res;             /** Result of expression evaluation **/

        printf("Enter A: ");

        printf("Enter B: ");

        printf("Enter C: ");

        printf("Enter D: ");

        res = calc(a,b,c,d);
        printf("The result is: %f\n\n",res);


double calc(double w, double x, double y, double z) {
        return ((w+x)*(w+x) + (y+z)*(y+z));
haielAuthor Commented:
Thanks alot.

Featured Post

IT Degree with Certifications Included

Aspire to become a network administrator, network security analyst, or computer and information systems manager? Make the most of your experience as an IT professional by earning your B.S. in Network Operations and Security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now