11/15/2010

BCT 1113 Solution for Assignment 3 (no 2 and 3)

* c*Note: code C++ tidak dapat di pamirkan dengan betul di sini.

2. 2. Write a function named CalSAP ( short for Calculate Sum, Average and Product) that have three arguments, prints the sum, the average and product. The function calling should be as follows

CalSAP (13,27,14);

and the following output should be displayed by function CalSAP.

Sum is 54

Average is 18

Product is 4914

Solutions

void kira(int a, int b, int c)

{

int sum, pro;

double avg;

sum = a+b+c;

pro=a*b*c;

avg=sum/3.0;

cout<<”Sum is “ <<

cout<<”Average is “ <<

cout<<”Product is “ <<

}

2. 3. Write a function named mutlak that computes and return the absolute difference of its two arguments, where the absolute difference of A and B is A – B if A is greater than B and B –A if B is greater than A. The function calling should be as follows

cout<

and the following output should be displayed by function mutlak.

4


Solutions

int mutlak(int a, int b)

{

if(a>b) return (a-b);

if(b>a) return (b-a);

}

No comments:

Cara download Installer windows 10 dalam format ISO

1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan.  ...