C++ Programming Exercises Basic Concepts
C++ Programming Exercises Basic Concepts
#include <iostream>
using namespace std;
int main()
{
cout << " Enter the limit of values N: "; //Prompt user to enter value for N
cin >> n;
cout << "\n"; cout<< endl;
sum=sum + j;
}
cout << "\n The Average is : " << average << endl; //Display average
return 0;
}
2)
/* Program that reads a value of N and computes average of next N
elements of inputs greater than 10 */
#include <iostream>
using namespace std;
int main()
{
cout << " Enter the limit of values N: "; //Prompt user to enter value for N
cin >> N;
cout << "\n"; cout<< endl;
cin >> n;
cout << "\n The Average is : " << average << endl;
return 0;
}
3)
Without Array
#include <iostream>
using namespace std;
int main()
{
//variables
int min, max;
int n, i, num;
min = INT_MAX; //assign maximum value for a int variable type to min
max = INT_MIN; //assign minimum value for a int variable type to max
if(num>max)
{
max = num;
}
if(num<min)
{
min = num;
}
}
#include<iostream>
using namespace std;
int main ()
{
int arr[10], n, i, max, min;
cout << "Enter the size of the array : "; cout << "\n";
cin >> n;
cout << "Enter the elements of the array : "; cout << "\n";
min = arr[0];
#include <iostream>
#include <bits/stdc++.h> //includes every standard library
using namespace std;
int main()
{
int N, i;
cout << "Enter number for N: "; //prompt user inputs for N
cin >> N;
return 0;
}
5)
/* Function to find Greatest Common Divisor
for 2 input integers */
#include <iostream>
using namespace std;
cout << "Input the 1st integer: "; //get user inputs and assign them
cin >> n1;
cout << "Input the 2nd integer: ";
cin >> n2;
cout << "Greatest Common Divisor: " << gcd << endl; //display gcd
}
int main()
{
greatestCommonDivisor(); //call the function
return 0;
}
6)
/* Function to compute smallest common factor
for 2 input integers */
#include <iostream>
using namespace std;
//display scf
cout << "Smallest Common Factor: " << scf << endl;
}
int main()
{
smallestCommonFactor(); //call the function
return 0;
}