Creating Square, Rectangle using * in C

In the process of learning the basic of C language people often create shapes using the *, and these shapes question are also asked in the interview question and selection exam of various companies so it is very good to learn how to make various shapes. Rectangle we can also make multiply. Multiply Code for the above images it is in the order of images. #include <iostream> using namespace std; int main() { int size; cout << "Enter Number "; cin >> size; cout << endl; for(int i=0;i<size;i++){ for(int j=0;j<size;j++){ cout << "*"; } cout << endl; } cout << endl; for(int i=0;i<size;i++){ for(int j=0;j<size;j++){ if(i == j) cout << "*"; else cout << " "; } cout << endl; } cout << endl; for(int i=0;i<size;i++){ for(int j=0;j<size;j++){ if( (size - i - 1) == j) cout << "*"; else cout << " "; } cout << endl; } cout << endl; for(int i=0;i<size;i++){ for(int j=0;j<size;j++){ if( (size - i - 1) == j || i == j) cout << "*"; else cout << " "; } cout << endl; } cout << endl; for(int i=0;i<size;i++){ for(int j=0;j<size;j++){ if(i==0 || i == (size -1)) // printing for the first and last line cout << "*"; else if((j == 0 && i !...

April 27, 2019 · 2 min · Rahul Rajput

Calculating Julian Day Number (JDN) using C++

What is Julian Day Number Julian Day is the continuous number of days since the beginning of the Julian period and is mainly used by astronomers and in software to easily calculate past days between two events (eg, food production date and sales by date). Code #include<iostream> #include <limits> using namespace std; void input_data(int &month, int &year, int &day,int &bmonth, int &byear, int &bday); void calculations(int month, int year, int day, int &jdn); void output_results(int &month, int &year, int &day, int &jdn,int d); void calculate_dow(int &jdn , int &dow); void calculate_difference_and_print(int jdn , int bjdn); void pause(); int main() { int bday; int bmonth; int byear; int bjdn; int day; int month; int year; int jdn; int dow; int bdow; input_data(month, year, day,bmonth, byear, bday); // calculate JDN for the present day calculations(month, year, day, jdn); // calculate JDN for the Date of birth calculations(bmonth, byear, bday, bjdn); calculate_dow(jdn,dow); calculate_dow(bjdn,bdow); cout << endl; output_results(month, year, day, jdn,dow); output_results(bmonth, byear, bday, bjdn,bdow); calculate_difference_and_print(jdn,bjdn); pause(); } void pause(); // this module is changed to increase the functionality void input_data (int &month, int &year, int &day,int &bmonth, int &byear, int &bday) { std::cout << "enter a month(jan = 1, feb = 2, etc....

April 27, 2019 · 3 min · Rahul Rajput

Split a string in C/C++ and Python

Splitting a string by some delimiter is a very common task in programmers day to day life. For example, we have an email address, and we want to extract email host which is part after @ in email address, example@gmail.com. After splitting this email address by “@”, there will be two strings “example”, “gmail.com”. Use case of string splitting contains, tokenizing things in compilers, extracting relevant data with Web crawlers etc....

December 11, 2018 · 1 min · Rahul Rajput

File handling in C++

In this tutorial, we are working with the files in the C++ or you have known to work with files as the file handling. File handling in any language requires Three main step to follow Open the file in Read/Write mode. Do various operation that you want to do. Close the file. So In CPP, you can also use the traditional approach of C using FILE pointer and etc....

December 9, 2018 · 2 min · Rahul Rajput