no
// declare a function int* function(int, int); or int* (function)(int, int); // declare a pointer to a function int* (*pointer_to_function)(int, int);
You took an example of The Product AB is determined as the dot products of the ith row in A and the jth column in B,placed in ith row and jth column of the resulting m x p matrix C. so: this may help you. #include <stdio.h> #include <stdlib.h> // function prototypes void Matrix_Mult( int a1[][3], int a2[][4], int a3[][4] ); void Matrix_MultAlt( int a1[][3], int a2[][4], int a3[][4] ); int dot3(const int a1[][3], const int a2[][4], int row, int col); void PrnNx4 (int ar[][4], int n); //--------------------------------------------------------------------------------- // Function: main(void) // Description: // demonstration of Matrix Multiplication // // Programmer: Paul Bladek // // Date: 10/31/2001 // // Version: 1.0 // // Environment: Hardware:IBM Pentium 4 // Software: Microsoft XP with .NET framework for execution; // Compiles under Microsoft Visual C++.Net 2005 // // Calls: Matrix_Mult(int a1[][3], int a2[][4], int a3[][4]) // Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4]) // PrnNx4(int ar[][4] // // // Parameters: int a1[][3] -- left matrix // int a2[][4] -- right matrix // int a3[][4] -- answer matrix // // Returns: EXIT_SUCCESS // ------------------------------------------------------------------------------ int main(void) { int A[2][3] = {{1, 3, 4}, {2, 0, 1}}, B[3][4] = {{1, 2, 3, 1}, {2, 2, 2, 2}, {3, 2, 1, 4}}, C[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; Matrix_Mult(A, B, C); PrnNx4(C, 2); Matrix_MultAlt(A, B, C); // alternate form that calls dot3 PrnNx4(C, 2); return EXIT_SUCCESS; } //--------------------------------------------------------------------------------- // Function: Matrix_Mult(int a1[][3], int a2[][4], int a3[][4]) // Description: // multiplies a 2X3 matrix by a 3X4 matrix // // Programmer: Paul Bladek // // Date: 10/31/2001 // // Version: 1.0 // // Environment: Hardware:IBM Pentium 4 // Software: Microsoft XP with .NET framework for execution; // Compiles under Microsoft Visual C++.Net 2005 // // Calls: None // // Called By: main() // // Parameters: int a1[][3] -- left matrix // int a2[][3] -- right matrix // int a3[][3] -- answer matrix // ------------------------------------------------------------------------------ void Matrix_Mult(int a1[][3], int a2[][4], int a3[][4]) { int i = 0; int j = 0; int k = 0; for(i = 0; i < 2; i++) for( j = 0; j < 4; j++) for( k = 0; k < 3; k++) a3[i][j] += a1[i][k] * a2[k][j]; } //--------------------------------------------------------------------------------- // Function: Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4]) // Description: // multiplies a 2X3 matrix by a 3X4 matrix -- Alternate Form // // Programmer: Paul Bladek // // Date: 10/31/2001 // // Version: 1.0 // // Environment: Hardware:IBM Pentium 4 // Software: Microsoft XP with .NET framework for execution; // Compiles under Microsoft Visual C++.Net 2005 // // Calls: dot3(const int a1[][3], const int a2[][4], int row, int col) // // Called By: main() // // Parameters: int a1[][3] -- left matrix // int a2[][3] -- right matrix // int a3[][3] -- answer matrix // ------------------------------------------------------------------------------ void Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4]) { int i = 0; int j = 0; for( i = 0; i < 2; i++) for( j = 0; j < 4; j++) a3[i][j] = dot3(a1, a2, i, j); } //--------------------------------------------------------------------------------- // Function: dot3(const int a1[][3], const int a2[][4], int row, int col) // Description: // dot product of a1 row and a2 col // // Programmer: Paul Bladek // // Date: 10/31/2001 // // Version: 1.0 // // Environment: Hardware:IBM Pentium 4 // Software: Microsoft XP with .NET framework for execution; // Compiles under Microsoft Visual C++.Net 2005 // // Calls: None // // Called By: Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4]) // // Parameters: int a1[][3] -- left matrix // int a2[][3] -- right matrix // int row -- the row number // int col -- the column number // // Returns: the dot product // ------------------------------------------------------------------------------ int dot3(const int a1[][3], const int a2[][4], int row, int col) { int k = 0; int sum = 0; for( k = 0; k < 3; k++) sum += a1[row][k] * a2[k][col]; return sum; } //--------------------------------------------------------------------------------- // Function: PrnNx4(int ar[][4], int n) // Description: // prints out an NX4 matrix // // Programmer: Paul Bladek // // Date: 10/31/2001 // // Version: 1.0 // // Environment: Hardware:IBM Pentium 4 // Software: Microsoft XP with .NET framework for execution; // Compiles under Microsoft Visual C++.Net 2005 // // Called By: main() // // Parameters: int ar[][4] -- matrix to print // int n -- number of elements // ------------------------------------------------------------------------------ void PrnNx4 (int ar[][4], int n) { int i = 0; int j = 0; for(i = 0; i < n; i++) { for( j = 0; j < 4; j++) printf("%4d", ar[i][j]); putchar('\n'); } }
printf ("sizeof (int) = %d\n", (int)sizeof (int));
The time.h include file is a header file for a library of standard time and date manipulation routines. For example... #include <stdio.h> #include <time.h> int main (int argc, char ** argv) { time_t tt = time(NULL); printf ("The date and time is %s", asctime(localtime(&tt))); return 0; }
int sum(int list[], int arraySize) { int sum=0; for(int i=0; i<arraySize; ++i ) sum+=list[i]; return(sum); }
One way to determine the day of week based on the date is to use Zeller's congruence. For the Gregorian calendar... int dayofweek (int month, int day, int year) { int weekday; if (month < 3) month += 12; weekday = day; weekday += int ((month + 1) * 26 / 10); weekday += year; weekday += int (year / 4); weekday += 6 * int (year / 100); weekday += int (year / 400); weekday %= 7; return weekday; /* 0 = Sunday, ..., 6 = Saturday */ }
Which of the following three C code snippets WILL NOT read a date as three integers as follows: int day, month, year;
int n1; int n2; int n3; int n4; int n5; int n6; int n7; int n8; int n9; int n10; int n11; int n12; int n13; int n14; int n15; int n16; int n17; int n18; int n19; int n20; int n21; int n22; int n23; int n24; int n25; int n26; int n27; int n28; int n29; int n30;
No, the first payment would be 6 months later on Jan 1.
Deferred int expenses is a term used in accounting for business and finance. It is used to refer to the interest on loans and payments, which is considered an expense that is deferred, or expected to be paid at a later date.
// declare a function int* function(int, int); or int* (function)(int, int); // declare a pointer to a function int* (*pointer_to_function)(int, int);
You took an example of The Product AB is determined as the dot products of the ith row in A and the jth column in B,placed in ith row and jth column of the resulting m x p matrix C. so: this may help you. #include <stdio.h> #include <stdlib.h> // function prototypes void Matrix_Mult( int a1[][3], int a2[][4], int a3[][4] ); void Matrix_MultAlt( int a1[][3], int a2[][4], int a3[][4] ); int dot3(const int a1[][3], const int a2[][4], int row, int col); void PrnNx4 (int ar[][4], int n); //--------------------------------------------------------------------------------- // Function: main(void) // Description: // demonstration of Matrix Multiplication // // Programmer: Paul Bladek // // Date: 10/31/2001 // // Version: 1.0 // // Environment: Hardware:IBM Pentium 4 // Software: Microsoft XP with .NET framework for execution; // Compiles under Microsoft Visual C++.Net 2005 // // Calls: Matrix_Mult(int a1[][3], int a2[][4], int a3[][4]) // Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4]) // PrnNx4(int ar[][4] // // // Parameters: int a1[][3] -- left matrix // int a2[][4] -- right matrix // int a3[][4] -- answer matrix // // Returns: EXIT_SUCCESS // ------------------------------------------------------------------------------ int main(void) { int A[2][3] = {{1, 3, 4}, {2, 0, 1}}, B[3][4] = {{1, 2, 3, 1}, {2, 2, 2, 2}, {3, 2, 1, 4}}, C[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; Matrix_Mult(A, B, C); PrnNx4(C, 2); Matrix_MultAlt(A, B, C); // alternate form that calls dot3 PrnNx4(C, 2); return EXIT_SUCCESS; } //--------------------------------------------------------------------------------- // Function: Matrix_Mult(int a1[][3], int a2[][4], int a3[][4]) // Description: // multiplies a 2X3 matrix by a 3X4 matrix // // Programmer: Paul Bladek // // Date: 10/31/2001 // // Version: 1.0 // // Environment: Hardware:IBM Pentium 4 // Software: Microsoft XP with .NET framework for execution; // Compiles under Microsoft Visual C++.Net 2005 // // Calls: None // // Called By: main() // // Parameters: int a1[][3] -- left matrix // int a2[][3] -- right matrix // int a3[][3] -- answer matrix // ------------------------------------------------------------------------------ void Matrix_Mult(int a1[][3], int a2[][4], int a3[][4]) { int i = 0; int j = 0; int k = 0; for(i = 0; i < 2; i++) for( j = 0; j < 4; j++) for( k = 0; k < 3; k++) a3[i][j] += a1[i][k] * a2[k][j]; } //--------------------------------------------------------------------------------- // Function: Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4]) // Description: // multiplies a 2X3 matrix by a 3X4 matrix -- Alternate Form // // Programmer: Paul Bladek // // Date: 10/31/2001 // // Version: 1.0 // // Environment: Hardware:IBM Pentium 4 // Software: Microsoft XP with .NET framework for execution; // Compiles under Microsoft Visual C++.Net 2005 // // Calls: dot3(const int a1[][3], const int a2[][4], int row, int col) // // Called By: main() // // Parameters: int a1[][3] -- left matrix // int a2[][3] -- right matrix // int a3[][3] -- answer matrix // ------------------------------------------------------------------------------ void Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4]) { int i = 0; int j = 0; for( i = 0; i < 2; i++) for( j = 0; j < 4; j++) a3[i][j] = dot3(a1, a2, i, j); } //--------------------------------------------------------------------------------- // Function: dot3(const int a1[][3], const int a2[][4], int row, int col) // Description: // dot product of a1 row and a2 col // // Programmer: Paul Bladek // // Date: 10/31/2001 // // Version: 1.0 // // Environment: Hardware:IBM Pentium 4 // Software: Microsoft XP with .NET framework for execution; // Compiles under Microsoft Visual C++.Net 2005 // // Calls: None // // Called By: Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4]) // // Parameters: int a1[][3] -- left matrix // int a2[][3] -- right matrix // int row -- the row number // int col -- the column number // // Returns: the dot product // ------------------------------------------------------------------------------ int dot3(const int a1[][3], const int a2[][4], int row, int col) { int k = 0; int sum = 0; for( k = 0; k < 3; k++) sum += a1[row][k] * a2[k][col]; return sum; } //--------------------------------------------------------------------------------- // Function: PrnNx4(int ar[][4], int n) // Description: // prints out an NX4 matrix // // Programmer: Paul Bladek // // Date: 10/31/2001 // // Version: 1.0 // // Environment: Hardware:IBM Pentium 4 // Software: Microsoft XP with .NET framework for execution; // Compiles under Microsoft Visual C++.Net 2005 // // Called By: main() // // Parameters: int ar[][4] -- matrix to print // int n -- number of elements // ------------------------------------------------------------------------------ void PrnNx4 (int ar[][4], int n) { int i = 0; int j = 0; for(i = 0; i < n; i++) { for( j = 0; j < 4; j++) printf("%4d", ar[i][j]); putchar('\n'); } }
printf ("sizeof (int) = %d\n", (int)sizeof (int));
int LCM3 (int a, int b, int c) { return LCM2 (a, LCM2 (b, c)); } int LCM2 (int a, int b) { return a*b/GCD2(a, b); }
The time.h include file is a header file for a library of standard time and date manipulation routines. For example... #include <stdio.h> #include <time.h> int main (int argc, char ** argv) { time_t tt = time(NULL); printf ("The date and time is %s", asctime(localtime(&tt))); return 0; }
int sum(int list[], int arraySize) { int sum=0; for(int i=0; i<arraySize; ++i ) sum+=list[i]; return(sum); }
#include<iostream> #include<string> enum day_enum{monday, tuesday, wednesday, thursday, friday, saturday, sunday}; enum mon_enum{january, february, march, april, may, june, july, august, september, october, november, december}; const std::string day_name[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; const std::string mon_name[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int main() { int date=1; // day of month int d=monday; int m=october; int y=2001; while(y<2014) { std::cout<<day_name[d].c_str()<<' '<<date<<' '<<mon_name[m].c_str()<<' '<<y<<std::endl; d=d<sunday?d+1:monday; ++date; if((date==32 ) (date==31 && (m==april m==june m==september m==november)) (m==february && (date==30 date==29 && y%4))) { date=1; m=m<december?m+1:january; if(m==january) ++y; } } }