Problem
Write a program to calculate square of an integer, input by the user. Declare a function with the name of square and should receive 3 integers. The function should then calculate the square of these three integers and return the square. Display the result.Code
#include "stdafx.h"#include <iostream>
#include<conio.h>
using namespace std;
void square (int *, int *, int *);
int main()
{
int a,b,c;
cout << "Enter 1st number: ";
cin >> a;
cout << "Enter 2nd number: ";
cin >> b;
cout << "Enter 3rd number: ";
cin >> c;
square (&a, &b, &c);
cout << "Square of Ist number = "<< a;
cout << "\nSquare of 2nd number = "<< b;
cout << "\nSquare of 3rd number = "<< c << endl ;
cout<<"Press any key to close.";
getch();
return 0;
}
void square (int *a, int *b, int *c)
{
*a = (*a * *a);
*b = (*b * *b);
*c = (*c * *c);
}
Output
Calculate Square of 3 input integers using function and pointers |
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.