Thursday, 12 May 2016

C++ Program of Array to Calculate Sum and Average of given Numbers

// 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:...
Share:

C++ Program of Array to Calculate Average of Numbers Using Arrays

#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;...
Share:

Monday, 9 May 2016

C++ Program to Find Even and Odd Elements in Array

#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++; } ...
Share:

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 ...
Share:

C++ Program of detecting a keypress and ASCII code

#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;    ...
Share:

Sunday, 8 May 2016

C++ Program to Find Max and Min Number in Array

#include<iostream>#include<cstdlib>#include<ctime>using namespace std;int main(){const int size=50;// array with size of 50int array[size];// for random numberssrand(time(0));    for(int i=0;i<size;i++){    // Initializing Array number is&nbs...
Share:

C++ Program of Multiplying Two Matrices using 2D Array

#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];    ...
Share:

C++ Program to add two matrix using 2-D arrays

#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&nb...
Share:

C++ Program to find the Area and Perimeter of a Rectangle

#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...
Share:

C++ Program to Find Reverse of Number

#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;     ...
Share:

C++ Program to Find Greatest Common Divisor (GCD) of two numbers

#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++){    &n...
Share: