Posts

Program to calculate the number of days from the beginning of the year to a date specified by the user through array in C++

Image
Using Visual Studio 2015 =============================================================== #include<iostream> using namespace std; #include<conio.h> void main() {  int day,month,totaldays;  int days_in_a_month[12]={31,28,31,30,31,30,31,31,30,31,30,31};  cout<<"Enter the month= ";  cin>>month;  cout<<"Enter the day (1 to 31) = ";  cin>>day;  totaldays=day;  for (int i = 0;i < month - 1;i++)  {      totaldays+=days_in_a_month[i];  }  cout<<"Total number of days are "<<totaldays;  _getche(); } ==========================================================================

Program to find average of sales in a week using array in C++

Image
Using Visual Studio 2015 =============================================================== #include<iostream> using namespace std; #include<conio.h> void main() {  const int size=7;  double arr[size],total=0,average;  for (int i = 0;i < size;i++)  {   cout<<"Enter number "<<i<<"=";   cin>>arr[i];  }  for (int j = 0;j < size;j++)  total+=arr[j];  average=total/size;   cout<<"Average="<<average;  _getche(); } ===========================================================================

Program to find equal values using if statement in C++

Image
Using Visual Studio 2015 =============================================================== #include<iostream> using namespace std; #include<conio.h> void main() {  int num1, num2, num3;  cout << "Enter first number= ";  cin >> num1;  cout << "Enter second number= ";  cin >> num2;  cout << "Enter third number= ";  cin >> num3;  if (num1==num2)  {   cout <<"\nFirst number is equal to second number";  }  if (num1 == num3)  {   cout <<"\nFirst number is equal to third number";  }  if (num2 == num3)  {   cout <<"\nSecond number is equal to third number";  }  _getche();  } ==========================================================================

Find the largest number out of three given values in C++

Image
Using Visual Studio 2015 =============================================================== #include<iostream> using namespace std; #include<conio.h> void main() {  int num1,num2,num3;  cout<<"Enter first number= ";  cin>>num1;  cout << "Enter second number= ";  cin >> num2;  cout << "Enter third number= ";  cin >> num3;  if (num1 > num2&&num1 > num3)  {   cout<<num1<<" is the largest number";  }  else if(num2 > num1&&num2 > num3)  {   cout << num2 << " is the largest number";  }  else if (num3 > num1&&num3 > num2)  {   cout << num3 << " is the largest number";  }  _getche(); } ==========================================================================

Program to convert seconds into hour, minute and second format in C++

Image
Using Visual Studio 2015 =============================================================== #include<iostream> using namespace std; #include<conio.h> void main() {  int sec,hour,min;  cout<<"Enter the seconds= ";  cin>>sec;  min=sec/60;  hour=min/60;  min=min%60;  sec=sec%60;  cout<<hour<<" Hours "<<min<<" minutes "<<sec<<" seconds";  _getch();   } =========================================================================

Binary Search in array C++

Image
Using Visual Studio 2015 =============================================================== #include <iostream> using namespace std; #include <conio.h> void main () {        int arr [10], as = 10, start = 0, end = 9, mid = (start + end) / 2, input;        bool check = false ;        for ( int i = 0; i < as; i++)        {        cout << "Enter the number " << (i+1) << "=" ;        cin >> arr[i];        }        cout << "Enter the value to search= " ;        cin >> input;        while (start <= end)        {               mid = (start + end) / 2;               if (input == arr[mid])               {                      check = true ;                      break ;               }               else if (input>arr[mid])               {                      start = mid + 1;               }               else if (input<arr[mid])     

Selection Sort of array in C++

Image
Using Visual Studio 2015 =============================================================== #include<iostream> using namespace std; #include<conio.h> int main() {  int i, j, n, loc, temp, min, arr[30];  cout << "Enter the number of elements:";  cin >> n;  for (i = 0;i<n;i++)  {   cout << "Enter the number=";   cin >> arr[i];  }  for (i = 0;i<n - 1;i++)  {   min = arr[i];   loc = i;   for (j = i + 1; j<n; j++)   {    if (min>arr[j])    {     min = arr[j];     loc = j;    }   }   temp = arr[i];   arr[i] = arr[loc];   arr[loc] = temp;  }  cout << "\nSorted list is as follows"<<endl;  for (i = 0;i<n; i++)  {   cout << arr[i] << " ";  }  _getche(); }      =========================================================================