Friday, July 31, 2009

Little c++ program?

Write a program that reads three integer values and passes these values to a function sum() by reference. The function sum() will calculate the sum of all the three values and returns the result to main() by reference.

Little c++ program?
Sounds like a school project... so here's some hints.





In main...


Read three integers, use CIN, read them into thre separate variables.


Define a fourth variable for the sum.


Call the sum function using all FOUR variables, passing the sum by reference.





In your function...


Define your function to accept four integers


Add the first three, put the answer into the fourth.
Reply:int * sum(int *,int *, int *);


void main()


{


int a,b,c;


clrscr();


printf("\nPlease Enter First Number : ");


scanf("%d",%26amp;a);


printf("\nPlease Enter The Second Number : ");


scanf("%d",%26amp;b);


printf("\nPlease Enter The Third Number :");


scanf("%d",%26amp;c);


printf("\nThe Sum is %d+%d+%d = %d",a,b,c,(sum(%26amp;a,%26amp;b,%26amp;c)));


getch();


}


int* sum(int * a, int *b, int *c)


{


return ((*a)+(*b)+(*c));


}

online florists

No comments:

Post a Comment