Posts

Showing posts from September, 2019

Distance between two points using user defined functions

Image
Distance between two points using user defined functions: To calculate the distance between two points by using user defined function's code is given below: Code: // Find the Distance between points. #include<iostream> #include<cmath> using namespace std; double distance(double x1, double x2, double y1, double y2); void main() { double x1, x2, y1, y2; cout << "Enter X1: "; cin >> x1; cout << "Enter X2: "; cin >> x2; cout << "Enter Y1: "; cin >> y1; cout << "Enter Y2: "; cin >> y2; cout << endl; cout << "Distance : " << distance(x1, x2, y1, y2); cout << endl; } double distance(double x1, double x2, double y1, double y2) { double distance; distance = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); return distance; } Download: To download this code click on the

Table printing of a number using user defined functions

Image
Table printing of a number using user defined functions code: //User-defined function to print Table of a number #include<iostream> using namespace std; void table(int y); void main() { int a; cout<<"Enter the number for Table"<<endl; cin>>a; table(a); } void table(int y) { for(int i=1;i<=10;i++) { cout<<y<<" * "<<i<<" = "<< y*i<<endl; } } Download: To download this code click on the given link below: Download

Finding maximum number by user defined function

Image
Code of Finding maximum number by user defined function: // Find Maximum Number #include<iostream> using namespace std; float find_max(float a, float b, float c); void main() { float a, b, c; cout << "Enter First Number: "; cin >> a; cout << "Enter Second Number: "; cin >> b; cout << "Enter Third Number: "; cin >> c; cout << endl; cout << "Largest Number is: " << find_max(a, b, c); cout << endl; } float find_max(float a, float b, float c) { if (a > b && a > c) return a; else if (b > a && b > c) return b; else return c; } Download: To download this code click on the given link below, Download

Power of the number by using user defined function

Image
Power of the number by using user defined function code is given below: // Power of a number using user-defined function #include<iostream> using namespace std; void power(int x, int y); int main() { int num, exp; cout << "enter any number : "; cin >> num; cout << "enter any exponent : "; cin >> exp; power(num, exp); } void power(int x, int y) { int c = 1; for (int i = 0; i < y; i++) { c = x*y; } cout << "Answer is : " << c << endl; } Download: To download thjs code click on the given link below: Download

Arithmetic operations using switch statement

Image
Arithmetic operations using switch statement code: // Arithmetic Operations using switch statement. # include <iostream> using namespace std; void main() { char option; float num1, num2; cout << "Enter first No : "; cin >> num1; cout << "Enter Second No : "; cin >> num2; cout << "Enter operator either :  + , - , * , /  = "; cin >> option; switch (option) { case '+': cout <<"Addition is : "<< num1 + num2<<endl; break; case '-': cout <<"Subtraction is : "<< num1 - num2<<endl; break; case '*': cout <<"Multiplication is : "<< num1 * num2<<endl; break; case '/': cout <<"Division is : "<< num1 / num2<<endl; break; default: cout << "Invalid Input"