// This program calculates the average of any number of numbers.
// Using the for structure
#include <iostream>
using namespace std;
#include <iostream>
int main()
{
int n, count;
float x, sum, avg;
sum = 0;
cout << "How many numbers? ";
cin >> n;
int size= n;
int array[size];
for (count=1; count<=n; count++){
cout << "Enter Number: ";
cin >> array[n];
sum = sum + array[n];
} //end for
cout << "The sum is " << sum << endl;
avg = sum / n;
cout << "The average is " << avg << endl;
system("pause");
return 0; //successful termination
}
Thursday, 12 May 2016
C++ Program of Array to Calculate Sum and Average of given Numbers
Afrasiyab Haider
May 12, 2016
array, array program, c++, C++ Program of Array to Calculate Sum and Average of given Numbers
No comments
C++ Program of Array to Calculate Average of Numbers Using Arrays
Afrasiyab Haider
May 12, 2016
array, array program, c++, c++ program, C++ Program of Array to Calculate Average of Numbers Using Arrays
No comments
#include <iostream>
using namespace std;
int main(){
int n, i;
float num[100], sum=0.0, average;
cout << "Enter the numbers of data: ";
cin >> n;
while (n>100 || n<=0)
{
cout << "Error! number should in range of (1 to 100)." << endl;
cout << "Enter the number again: ";
cin >> n;
}
for(i=0; i<n; ++i)
{
cout << i+1 << ". Enter number: ";
cin >> num[i];
sum+=num[i];
}
average=sum/n;
cout << "Average = " << average;
return 0;
}
Monday, 9 May 2016
C++ Program to Find Even and Odd Elements in Array
Afrasiyab Haider
May 09, 2016
array, array program, c++, c++ program, C++ Program to Find Even and Odd Elements in Array
No comments
#include<iostream.h> #include<conio.h> void main() { int arr[20],even[20],odd[20],i,j=0,k=0,no; clrscr(); cout<<"How Size of Array: "; cin>>no; cout<<"Enter any "<<no<<" elements in Array: "; for(i=0; i<no;i++) { cin>>arr[i]; } for(i=0; i<no;i++) { if(arr[i]%2==0) { even[j]=arr[i]; j++; } else { odd[k]=arr[i]; k++; } } cout<<"\nEven Elements: "; for(i=0; i<j ;i++) { cout<<even[i]<<" "; } cout<<"\nOdd Elements: "; for(i=0; i<k; i++) { cout<<odd[i]<<" "; } getch(); }
C++ Program Of Calculator
#include <iostream> using namespace std; int addition (int num1, int num2); int subtraction (int num1, int num2); int division (int num1, int num2); int multiplication(int num1, int num2); int main() { char option; int num1, num2, result; cout<<"\n\t\t\tSimple calculator"<<endl; do { cout<<"Enter + for Addtion\nEnter - for Subtraction\n Enter / for Division\nEnter * for Multiplication\n Enter E to EXIT\n"; cout<<"\n\t\t\tEnter Option: "; cin>>option; if(option!='e'&&option!='E') { cout<<"\n\t\t\tEnter First Number: "; cin>>num1; cout<<"\n\t\t\tEnter Second Number: "; cin>>num2; } if(option!='+'&&option!='-'&&option!='/' &&option!='*'&&option!='e'&&option!='E') { cout<<"\n\t\t\tSELECT the VALID OPTION\n"; } else if(option=='+') { result=addition(num1,num2); cout<<"\n\t\t\t"<<num1<<" + "<<num2<<" = "<<result<<endl; } else if(option=='-') { result=subtraction(num1,num2); cout<<"\n\t\t\t"<<num1<<" - "<<num2<<" = "<<result<<endl; } else if(option=='/') { result=division(num1,num2); cout<<"\n\t\t\t"<<num1<<" / "<<num2<<" = "<<result<<endl; } else if(option=='*') { result=multiplication(num1,num2); cout<<"\n\t\t\t"<<num1<<" X "<<num2<<" = "<<result<<endl; } }while(option!='e'&&option!='E'); cout<<"\n\t\t\tProgram EXIT Successfully.......\n\t\t\t"; return 0; } int addition(int num1, int num2) { return (num1+num2); } int subtraction(int num1, int num2) { return (num1-num2); } int division(int num1, int num2) { if(num2==0) { cout<<"\n\t\t\tDivide by ZERO not allowed :"<<endl; return 0; } return (num1/num2); } int multiplication(int num1, int num2) { return (num1*num2); }
C++ Program of detecting a keypress and ASCII code
Afrasiyab Haider
May 09, 2016
c++, c++ program, C++ Program of detecting a keypress and ASCII code
No comments
- #include<iostream>
- #include<conio.h>
- using namespace std;
- int main()
- {
- char key_press;
- int ascii_value;
- cout<<"\n\t\t\tPress Any Key To Check Its ASCIValue\n\n\t\t\tPress ESC to EXIT\n\n\n";
- while(1)
- {
- key_press=getch();
- ascii_value=key_press;
- if(ascii_value==27) // For ESC
- break;
- cout<<"\t\t\tKEY Pressed-> \" "<<key_press<<" \" Ascii Value = "<<ascii_value<<"\n\n";
- }
- return 0;
- }
Sunday, 8 May 2016
C++ Program to Find Max and Min Number in Array
Afrasiyab Haider
May 08, 2016
array, array program, c++, c++ program, C++ Program to Find Max and Min Number in Array
No comments
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
const int size=50;
// array with size of 50
int array[size];
// for random numbers
srand(time(0));
for(int i=0;i<size;i++){
// Initializing Array number is less than 100
array[i]=rand()%100;
// Displaying array value
cout<<array[i]<<endl;
}
// initializing max, min
int max=array[0];
int min=array[0];
/* scanning array to find
minimum and maximum
number */
for(int i=0;i<size;i++){
// finding minimum number in array
if(min>array[i]){
min=array[i];
}
//finding maximum number in array
if(max<array[i]){
max=array[i];
}
}
// displaying output
cout<<"Maximum Number is :"<<max<<endl;
cout<<"Minimum Number is:"<<min<<endl;
return 0;
}
C++ Program of Multiplying Two Matrices using 2D Array
Afrasiyab Haider
May 08, 2016
2D array, array, array program, c++, c++ program, C++ Program of Multiplying Two Matrices using 2D Array
No comments
#include<iostream>
using namespace std;
int main(){
//Using const int for array size
const int row=2,col=2;
// if not use const error found
cout<<"Size of Matrices : "<<row<<" X "<<col<<endl;
cout<<"Enter Value For FirstMatrix Matrix:"<<endl;
int firstMatrix[row][col];
int secondMatrix[row][col];
int resultantMatrix[row][col], var;
int i,j;
for( i=0;i<row;i++){
cout<<"Enter value for row number: "<<i+1<<endl;
for( j=0;j<col;j++){
cin>>firstMatrix[i][j];
}
}
cout<<"\n\n\nEnter Value For SecondMatrix Matrix:"<<endl;
for( i=0;i<row;i++){
cout<<"Enter value for row number: "<<i+1<<endl;
for( j=0;j<col;j++){
cin>>secondMatrix[i][j];
}
}
var=0;
// ResultantMatrixant Matrix
for( i=0;i<row;i++){
for( j=0;j<col;j++){
for(int k=0;k<row;k++){
var=var+(firstMatrix[i][k]*secondMatrix[k][j]);
cout<<var<<endl;
}
resultantMatrix[i][j]=var;
var=0;
}
}
cout<<"\n\n\t\tResultant Matrix:"<<endl;
for( i=0;i<row;i++){
cout<< endl;
for( j=0;j<col;j++){
cout<<"\t\t"<<resultantMatrix[i][j]<<" ";
}
}
return 0;
}
C++ Program to add two matrix using 2-D arrays
Afrasiyab Haider
May 08, 2016
2D array, array, array program, c++, c++ program, C++ Program to add two matrix using 2-D arrays
No comments
#include
<iostream>
using namespace std;
int
main(){
//Using const int for array size
const int
row=
2
,col=
2
;
// if not use const error found
cout<<
"Size of Matrices : "
<<row<<
" X "
<<col<<endl;
cout<<
"Enter Value For First Matrix:"
<<endl;
int
first[row][col], second[row][col];
int
i,j;
for
( i=
0
;i<row;i++){
cout<<
"Enter value for row number: "
<<i+
1
<<endl;
for
( j=
0
;j<col;j++){
cin>>first[i][j];
}
}
cout<<
"\n\n\nEnter Value For
Second Matrix:"
<<endl;
for
( i=
0
;i<row;i++){
cout<<
"Enter value for row number: "
<<i+
1
<<endl;
for
( j=
0
;j<col;j++){
cin>>second[i][j];
}
}
// Resultant Matrix
for
( i=
0
;i<row;i++){
for
( j=
0
;j<col;j++){
first[i][j]=first[i][j]+second[i][j];
}
}
cout<<
"\n\n\t\tResultant Matrix:"
<<endl;
for
( i=
0
;i<row;i++){
cout<< endl;
for
( j=
0
;j<col;j++){
cout<<
"\t\t"
<<first[i][j]<<
" "
;
}
}
return
0
;
}
C++ Program to find the Area and Perimeter of a Rectangle
Afrasiyab Haider
May 08, 2016
c++, c++ program, C++ program to find the Area and Perimeter of a Rectangle:
No comments
#include<iostream>
using namespace std;
int main()
{
int width,height,area,perimeter;
cout<<"Enter Width of Rectangle = ";
cin>>width;
cout<<"Enter Height of Rectangle = ";
cin>>height;
area=height*width;
cout<<"Area of Rectangle ="<<area<<endl;
perimeter=2*(height+width);
cout<<" Perimeter of rectangle are = "<<perimeter<<endl;
return 0;
}
C++ Program to Find Reverse of Number
Afrasiyab Haider
May 08, 2016
c++, c++ program, C++ Program to Find Reverse of Number, Reverse of Number
No comments
#include<iostream>
using namespace std;
int main() {
int number, reverse = 0;
cout<<"Input a Number to Reverse and press Enter: ";
cin>> number; // Taking Input Number in variable number
for( ; number!= 0 ; )
{
reverse = reverse * 10;
reverse = reverse + number%10;
number = number/10;
}
cout<<"New Reversed Number is: "<<reverse;
return 0;
}
using namespace std;
int main() {
int number, reverse = 0;
cout<<"Input a Number to Reverse and press Enter: ";
cin>> number; // Taking Input Number in variable number
for( ; number!= 0 ; )
{
reverse = reverse * 10;
reverse = reverse + number%10;
number = number/10;
}
cout<<"New Reversed Number is: "<<reverse;
return 0;
}
C++ Program to Find Greatest Common Divisor (GCD) of two numbers
Afrasiyab Haider
May 08, 2016
c++, c++ program, C++ Program to Find Greatest Common Divisor (GCD) of two numbers, GCD Program
No comments
#include<iostream>
using namespace std;
int main() {
int first_number;
cout<<"Enter First Number : ";cin>>first_number;
int second_number;
cout<<"Enter Second Number: ";cin>>second_number;
int gcd;
for(int i=1;i<=first_number&&i<=second_number;i++){
if(first_number%i==0 && second_number%i == 0 ){
gcd=i;
}
}
cout<<"Greatest Common Divison (GCD):"<<gcd<<endl;
return 0;
}
using namespace std;
int main() {
int first_number;
cout<<"Enter First Number : ";cin>>first_number;
int second_number;
cout<<"Enter Second Number: ";cin>>second_number;
int gcd;
for(int i=1;i<=first_number&&i<=second_number;i++){
if(first_number%i==0 && second_number%i == 0 ){
gcd=i;
}
}
cout<<"Greatest Common Divison (GCD):"<<gcd<<endl;
return 0;
}
Subscribe to:
Posts (Atom)
Search
Popular Posts
-
In this program we will learn how to insert and delete data in a stack. Stack works on the principal of LIFO last in first out so new data ...
-
#include <iostream> using namespace std ; int main (){ int n , i ; float num [ 100 ], sum = 0.0 , average ; ...
-
In this program we will learn how to search a number from indexes of array. The code is given below. //Code Starts #include <ios...
-
In this program we will learn how to take exponential of a variable e.g 10^2. The code is given below. //Code starts #include<i...
-
In this program we will learn how to calculate sum, multiply and average of numbers stored in array. The code is given below. //Code...
-
#include<iostream> using namespace std; int main(){ //Using const int for array size const int row=2,col=2; // if not use const e...
-
In this program we will learn, how to call a structure inside a function and insert its values outside the main().. The code is given belo...
-
// This program calculates the average of any number of numbers. // Using the for structure #include <iostream> using namespace ...
-
#include <iostream> using namespace std ; int main () { // an array with 5 rows and 2 columns. int a [ 5 ][ 2 ] = ...
-
#include<iostream> using namespace std; int main() { int number, reverse = 0; cout<<"Input a Number to Reverse and press E...
All posts
-
►
2019
(1)
- ► 03/10 - 03/17 (1)
-
►
2017
(32)
- ► 07/02 - 07/09 (8)
- ► 05/14 - 05/21 (3)
- ► 03/05 - 03/12 (1)
- ► 02/26 - 03/05 (6)
- ► 02/19 - 02/26 (2)
- ► 02/12 - 02/19 (12)
-
▼
2016
(36)
- ► 10/23 - 10/30 (1)
- ► 06/12 - 06/19 (4)
- ► 05/29 - 06/05 (1)
- ► 05/22 - 05/29 (1)
- ► 05/15 - 05/22 (1)
-
▼
05/08 - 05/15
(11)
- C++ Program of Array to Calculate Sum and Average ...
- C++ Program of Array to Calculate Average of Numbe...
- C++ Program to Find Even and Odd Elements in Array
- C++ Program Of Calculator
- C++ Program of detecting a keypress and ASCII code
- C++ Program to Find Max and Min Number in Array
- C++ Program of Multiplying Two Matrices using 2D A...
- C++ Program to add two matrix using 2-D arrays
- C++ Program to find the Area and Perimeter of a Re...
- C++ Program to Find Reverse of Number
- C++ Program to Find Greatest Common Divisor (GCD) ...
- ► 05/01 - 05/08 (8)
- ► 04/24 - 05/01 (9)
I Am
Welcome
Tags
2D array
6 in 1
array
array program
ASCII
binary
binary search
bubble sort
c++
C++ code to print right triangle shape using nested for loops
c++ program
C++ Program of Array to Calculate Average of Numbers Using Arrays
C++ Program of Array to Calculate Sum and Average of given Numbers
C++ Program of Array to Find How Many Integers are Equal or Greater than 10
C++ Program of Array to Sort 10 Integers in Descending Order
C++ Program Of Calculator
C++ Program of detecting a keypress and ASCII code
c++ program of for loop
C++ Program of Multiplying Two Matrices using 2D Array
C++ Program of sorting values in array
C++ Program of Starric using for loop
C++ Program of Two Dimensional Array
C++ Program to add two matrix using 2-D arrays
C++ Program to Find Even and Odd Elements in Array
C++ Program to Find Greatest Common Divisor (GCD) of two numbers
C++ Program to Find Max and Min Number in Array
C++ Program to Find Reverse of Number
C++ program to find the Area and Perimeter of a Rectangle:
C++ Program to Sort Distorted Array
calculator
circle
circular queue
class
creation
deletion
even odd
example program
exponential
for loop
function
functions
GCD Program
hero formula
inheritance
insertion
insertion sort
linked list
nested for loop
oop
pointer
polymorphism
prime number
prime number program in c++
printing
program
queue
recursion
recursive function
reverse
Reverse of Number
selection sort
sequential search
sort
stack
starric
structure
template
Trees
triangle
two dimensional array