Heyyyyy! Just staying away from the computer for a while (exams...).. Will be back in some days!
Code the world away guys!!!
:)
Code the world away guys!!!
:)
#include<iostream> #include<cstdlib> using namespace std; int main() { int mat[100][100],tr=0,i,j,m,n; cout<<"Enter the order of the matrix : \n"; cin>>m>>n; while(m!=n){ cout<<"Not a square matrix!\n"; exit(0); } cout<<"Enter the elements of the matrix : \n"; for(i=0;i<m;i++){ for(j=0;j<n;j++){ cin>>mat[i][j]; } } cout<<"The matrix is : \n"; for(i=0;i<m;i++){ for(j=0;j<n;j++){ cout<<mat[i][j]; cout<<"\t"; } cout<<endl; } for(i=0;i<m;i++){ for(j=0;j<n;j++){ if(i==j){ tr = tr + mat[i][j]; } } } cout<<"The trace is "<<tr; }
#include<iostream> #include "process.h"; using namespace std; int main() { int days_in_months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int day1, day2; int month1, month2; int year1, year2; int y_diff, d_diff; int tot_mon; int years = 365; cout<<"Program to calculate how many days are in between the day/month/year entered"<<endl; cout<<endl; start: cout<<"Please enter the date by day, month, year"<<endl; cout<<endl; cout<<"First date : "<<endl; cout<<endl; cout<<"Day : "; cin>>day1; if(day1 > 31 || day1 <= 0) { cout<<"Incorrect day entered"<<endl; cin.ignore(); return 0; } cout<<"Month: "; cin>>month1; if(month1 > 12 || month1 <= 0) { cout<<"Incorrect Month entered"<<endl; cin.ignore(); return 0; } cout<<"Year: "; cin>>year1; if(year1 > 9999 || year1 < 0) { cout<<"Incorrect Year Entered"<<endl; cin.ignore(); return 0; } cout<<endl; cout<<"\nSecond date:: "<<endl; cout<<endl; cout<<"Day: "; cin>>day2; if(day2 > 31 || day2 <= 0) { cout<<"Incorrect day entered"<<endl; cin.ignore(); return 0; } cout<<"Month: "; cin>>month2; if(month2 > 12 || month2 <= 0) { cout<<"Incorrect Month entered"<<endl; cin.ignore(); return 0; } cout<<"Year: "; cin>>year2; if(year2 > 9999 || year2 < 0) { cout<<"Incorrect Year Entered"<<endl; cin.ignore(); return 0; } if(year1 == year2) { y_diff = 0; } else { if(year1 % 4 == 0 && year1 % 100 != 0 || year1 % 400 == 0) { if(year2 % 4 == 0 && year2 % 100 != 0 || year2 % 400 == 0) { if(year1 > year2) { y_diff = (year1 - year2) * (years) + 2; } else { y_diff = (year2 - year1) * (years) + 2; } if(month2 > month1) { if(days_in_months[month1 - 1] > days_in_months[1]) { --y_diff; } } } else { if(year1 > year2) { y_diff = (year1 - year2) * (years) + 1; } else { y_diff = (year2 - year1) * (years) + 1; } if(month1 > month2) { if(days_in_months[month2 - 1] > days_in_months[1]) { --y_diff; } } } } else { if(year1 > year2) { y_diff = (year1 - year2) * (years); } else { y_diff = (year2 - year1) * (years); } } } if(month1 == month2) { tot_mon = 0; } else { if(month1 > month2) { for(int i = (month1 - 1); i > (month2 - 1); i--) { static int tot_mon_temp = 0; tot_mon_temp += days_in_months[i]; tot_mon = tot_mon_temp; } } else { for(int i = (month1 - 1); i < (month2 - 1); i++) { static int tot_mon_temp = 0; tot_mon_temp += days_in_months[i]; tot_mon = tot_mon_temp; } } } int days_total; if (day1 == day2) { d_diff = 0; days_total = (y_diff + tot_mon) - d_diff; } else { if(day1 > day2) { d_diff = day1 - day2; days_total = (y_diff + tot_mon) - d_diff; } else { d_diff = day2 - day1; days_total = (y_diff + tot_mon) + d_diff; } } if(year1 == year2) { } else { if(year1 > year2) { for(int i = (year2 + 1); i < year1; i++) { if(i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { cout<<endl; cout<<i<<endl; ++days_total; } } } else { for(int i = (year1 + 1); i < year2; i++) { if(i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { cout<<endl; cout<<i<<endl; ++days_total; } } } } here: cout<<"\nInclude the end date? (Y/N) : "; char ch; cin>>ch; if(ch=='Y'||ch=='y') { cout<<endl; cout<<"\nThe total days in between your dates are: "<<days_total<<endl; cout<<endl; } else if(ch=='N'||ch=='n') { cout<<endl; cout<<"\nThe total days in between your dates are: "<<(days_total-1)<<endl; cout<<endl; } else { cout<<"Invalid choice, try again!"; goto here; } here2: cout<<"\n\nCheck with another pair of dates? (Y/N)"<<endl; char ch2; cin>>ch2; if(ch2=='Y'||ch2=='y') { goto start; } else if(ch2=='N'||ch2=='n') { exit(0); } else { cout<<"Invalid choice, try again!"; goto here2; } cin.get(); cin.ignore(); return 0; }
switch(expression){case constant - 0:
#include<iostream> #include "conio.h"; using namespace std; int main() { int ch; cout<<"Enter the number of the day\n"; cin>>ch; switch(ch) { case 1: cout<<"Sunday"; break; case 2: cout<<"Monday"; break; case 3: cout<<"Tuesday"; break; case 4: cout<<"Wednesday"; break; case 5: cout<<"Thursday"; break; case 6: cout<<"Friday"; break; case 7: cout<<"Saturday"; break; } getch(); }Working: