C++ Program find if file exists of not
In this post we will see how to write a C++ code to check if the file exists in the […]
C++ Tutorial for Beginners – Learning C++ in simple and easy steps : A beginner’s tutorial containing complete knowledge of C++ Syntax Object Oriented Language, Methods, Overriding, Inheritance, Polymorphism, Interfaces, STL, Iterators, Algorithms, Exception Handling, Overloading,Templates, Namespaces and Signal Handling
In this post we will see how to write a C++ code to check if the file exists in the […]
Basic Idea Pick one element in the array, which will be the pivot. Make one pass through the array, called […]
Merge sort Merge sort algorithm is one of two important divide-and-conquer sorting algorithms (the other one is quick sort).Merge MergeIt […]
Selection Sort Algorithm using C++ Selection Sort Repeatedly searches for the largest value in a section of the data Moves […]
Insertion Sort Idea: Start at position 1 and move each element to the left until it is in the correct […]
The bubble sort Algorithm simply compares adjacent elements and exchanges them if they are out of order. To apply the Bubble […]
In this example we will learn how to Display current date and time using C++.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
#include<iostream> #include<cmath> #include <ctime> using namespace std; int main() { time_t t = time(NULL); tm* timePtr = localtime(&t); cout << "seconds= " << (timePtr->tm_sec) << endl; cout << "minutes = " << (timePtr->tm_min) << endl; cout << "hours = " << (timePtr->tm_hour) << endl; cout << "day of month = " << (timePtr->tm_mday) << endl; cout << "month of year = " << (timePtr->tm_mon)+1 << endl; cout << "year = " << (timePtr->tm_year)+1900 << endl; cout << "weekday = " << (timePtr->tm_wday )<< endl; cout << "day of year = " << (timePtr->tm_yday )<< endl; cout << "daylight savings = " <<(timePtr->tm_isdst )<< endl; cout << endl; cout << endl; cout << "Date " <<(timePtr->tm_mday)<<"/"<< (timePtr->tm_mon)+1 <<"/"<< (timePtr->tm_year)+1900<< endl; cout << "Time " << (timePtr->tm_hour)<<":"<< (timePtr->tm_min)<<":"<< (timePtr->tm_sec) << endl; return 0; } /* OUTPUT seconds= 6 minutes = 32 hours = 17 day of month = 4 month of year = 7 year = 2016 weekday = 1 day of year = 185 daylight savings = 1 Date 4/7/2016 Time 17:32:6 */ |
C++ […]
C++ Examples – Sum of ODD Numbers in the Given Range
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#include<stdio.h> #include <iostream> using namespace std; int main(){ int number; int min,max; long sum =0; cout << "Enter the minimum range: "; cin >> min; cout << "Enter the maximum range: "; cin >> max; for(number = min;number <= max; number++) if(number % 2 !=0) sum = sum + number; cout << "Sum of odd numbers in given range is: " << sum; return 0; } /* OUTPUT Enter the minimum range: 25 Enter the maximum range: 30 Sum of odd numbers in given range is: 81 */ |
Different Ways of asking above question C++ – […]
Random number generator using C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#include<iostream> #include<time.h> #include<stdlib.h> #define MAX_NUM 10 using namespace std; void randnum() { int random; srand(time(NULL)); for(int i=0;i<10;i++) { random=rand()%MAX_NUM; cout<<random<<endl; } } int main() { cout<<"The ten random number are "<<endl; randnum(); return 0; } /* OUTPUT The ten random number are 3 0 8 9 6 4 8 8 8 0 */ |
Different ways the Above question can be asked Random number generator – C++ C++ […]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
#include<iostream> using namespace std; int main(){ //declaring array int array[5]; cout<<"Enter 5 numbers randomly : "<<endl; for(int i=0; i<5; i++) { //Taking input in array cin>>array[i]; } cout<<endl; cout<<"Input array is: "<<endl; for(int j=0; j<5; j++) { //Displaying Array cout<<"\t\t\tValue at "<<j<<" Index: "<<array[j]<<endl; } cout<<endl; // Bubble Sort Starts Here int temp; for(int i2=0; i2<=4; i2++) { for(int j=0; j<4; j++) { //Swapping element in if statement if(array[j]>array[j+1]) { temp=array[j]; array[j]=array[j+1]; array[j+1]=temp; } } } // Displaying Sorted array cout<<" Sorted Array is: "<<endl; for(int i3=0; i3<5; i3++) { cout<<"\t\t\tValue at "<<i3<<" Index: "<<array[i3]<<endl; } return 0; } /* OUTPUT Enter 5 numbers randomly : 55 65 12 37 26 Input array is: Value at 0 Index: 55 Value at 1 Index: 65 Value at 2 Index: 12 Value at 3 Index: 37 Value at 4 Index: 26 Sorted Array is: Value at 0 Index: 12 Value at 1 Index: 26 Value at 2 Index: 37 Value at 3 Index: 55 Value at 4 Index: 65 */ |
Bubble sort examines the array from start to finish, comparing elements as it goes. Any time it finds […]
In this example we will learn how to Check if the particular number is Palindrome or not. C++ – PALINDROMIC NUMBERS […]
In this example we will see how to print Floyd’s Triangle using C++.
1 2 3 4 5 6 |
1 2 3 3 4 5 4 5 6 7 5 6 7 8 9 6 7 8 9 10 11 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include <iostream> using namespace std; int main() { int rows,i,j,k=0; cout<<"Enter number of rows: "; cin>>rows; for(i=1;i<=rows;i++) { for(j=1;j<=i;++j) cout<<k+j<<" "; ++k; cout<<endl; } return 0; } /* OUTPUT Enter number of rows: 6 1 2 3 3 4 5 4 5 6 7 5 6 7 8 9 6 7 8 9 10 11 */ |
After you write a […]
C++ Program Write a Program to Enter Char or Number and Check its ASCII Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> using namespace std; int main(){ char ascii; int numeric; cout << "Give character: "; cin >> ascii; cout << "Its ascii value is: " << (int) ascii << endl; cout << "Give a number to convert to ascii: "; cin >> numeric; cout << "The ascii value of " << numeric << " is " << (char) numeric; return 0; } /* OUTPUT Give character: c Its ascii value is: 99 Give a number to convert to ascii: 97 The ascii value of 97 is a */ |
Different ways of […]
Simple star pattern programs in C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include <iostream> using namespace std; const int STARS_PER_LINE = 10; const int NUM_LINES = 5; int main() { int stars_printed, lines_printed; lines_printed = 0; while ( lines_printed < NUM_LINES ) { stars_printed = 0; while ( stars_printed < STARS_PER_LINE ) { cout << '*'; stars_printed++; } cout << endl; lines_printed++; } return 0; } /* OUTPUT ********** ********** ********** ********** ********** */ |
Different ways of asking the above question Program to print various types of […]
In this example we will learn C++ Program to Find Cube Root of Number. In the first example we will […]
Copyright © 2021 | WordPress Theme by MH Themes