Gauss Elimination method for solving n-linear equations in C language

This is a simple C language program that calculates solution of n-linear equations using Non-pivotal Gauss Elimination method. It uses upper triangular matrix to do so, for solution using lower triangular matrix visit here.

#include<stdio.h> #include<conio.h> float matrix[10][10], m, temp[10]; int i, j, k, n; void upper_triangularization() { for (i=0; i<n-1; i++) for (j=i+1; j<n; j++) { m = matrix[j][i]/matrix[i][i]; for (k=0; k<n+1; k++) { matrix[j][k] = matrix[j][k]-(m*matrix[i][k]); } } } //upper_traingulisation void back_subsitution() { for (i=n-1; i>=0; i--) { m = matrix[i][n]; for (j=n-1; j>i; j--) m = m - temp[n-j] * matrix[i][j]; temp[n-i] = m/matrix[i][i]; printf("\n x%d => %f", i+1, temp[n-i]); } } // back_subsitution void main() { printf("Enter number. of variables :: "); scanf("%d", &n); printf("Enter the augmented matrix: \n"); for (i=0; i<n; i++) for (j=0; j<n+1; j++) scanf("%f", &matrix[i][j]); upper_triangularization(); printf("The upper traingular matrix is : \n"); for (i=0; i<n; i++) { for (j=0; j<n+1; j++) printf("%f \t", matrix[i][j]); printf("\n"); } printf("The required result is : \n"); back_subsitution(); getch(); } // main

Insertion And Deletion Operation Over Multiple Queue In C language

A simple C language program to implement multiple queues in a single dimension array.
This is a revised version of Insertion And Deletion Operation Over Multiple Queue | multiple queue in data structure.

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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 
#include<stdio.h> #include<conio.h> # define max 20   int insq (int queue[max], int qno, int rear[], int limit[], int *data) { if (rear[qno] == limit[qno]) return(-1); else { rear[qno]++; //... rear[qno] = rear[qno] + 1; queue[ rear[qno] ] = *data; return(1); } // else } // insq   int delq (int queue[max], int qno, int front[], int rear[], int *data) { if( front[qno] == rear[qno] ) return(-1); else { front[qno]++; //... front[qno] = front[qno] + 1; *data = queue[ front[qno] ]; return(1); } // else } // delq   int getQueueNumber(int n) { int qNo=0; Inva: printf("\n Enter a Logical Queue Number (1 to %d) : ", n); scanf("%d", &qNo); if (qNo<1 || qNo >n) { printf(" Invalid Queue Number. Please try again.\n"); goto Inva; } return qNo; }   void main() { int queue[max], data; int bott[10], limit[10], f[10], r[10]; int i, n, qno, size, option, reply;   printf("\n C Language program to implement the Multiple Queues \n"); printf("\n How Many Queues ? : "); scanf("%d", &n); size = max / n; //... Get Max. size for each Queue   //... Initialize bottom for each Queue   bott[0] = -1; //... Bottom of first Queue is -1 for(i = 1; i < n; i++) bott[i] = bott[i-1] + size;   //... Initialize Limit of each Queue   for(i = 0; i < n; i++) //... Limit of i'th Queue is equal to bottom of i'th Queue + Size limit[i] = bott[i] + size;   //... Initialize Front & Rear of each Queue //... Initial value of Front & Rear of each Queue is same as its Bottom Value   for(i = 0; i < n; i++) f[i] = r[i] = bott[i];   //... Process the Queues   do { printf("\n\n C Language program to implement the Multiple Queues \n"); printf("\n 1. Insert in a Queue"); printf("\n 2. Delete from a Queue"); printf("\n 3. Print from a Queue"); printf("\n 3. Exit \n"); printf("\n Select proper option ( 1 / 2 / 3 / 4) : "); scanf("%d", &option); switch(option) { case 1 : //... Insert qno = getQueueNumber(n); printf("\n Enter Data : "); scanf("%d", &data); reply = insq(queue, qno-1, r, limit, &data); if( reply == -1) printf("\n Queue %d is Full \n", qno); else printf("\n %d is inserted in a Queue No. %d \n", data, qno); break; case 2 : //... Delete qno = getQueueNumber(n); reply = delq(queue, qno-1, f, r, &data); if( reply == -1) printf("\n Queue %d is Empty \n", qno); else printf("\n %d is deleted from Queue No. %d \n", data, qno); break; case 3: qno = getQueueNumber(n); printf("\n Elements of Queue %d are as : ", qno); if (f[qno-1]==r[qno-1]) { printf("\n Queue is empty"); break; } for (i=f[qno-1]+1; i<=r[qno-1]; i++) printf("%d\t", queue[i]); printf("\n"); break; case 4 : break; default: printf("\n Invalid input. Please try again."); } // switch }while(option!=4); } // main

Getting started development on android with eclipse

Android ImageThis post is just a quickie on how to get yourself started with Android development and the step-by-step guide about the basic tools needed to do so. Now there are many ways using which you can start development. But the simplest way is using Eclipse IDE. So, here’s a simple guide for a complete beginner.

For a complete beginner, it would be best to get eclipse and android sdk using this full-felged suite (eclipse, ADT, SDK Manager combined all together), in which case the first four steps of this tutorial can be skipped. Or download each tool separately, and continue with the steps given below.

Step 1. Download Eclipse
Although there are a lot of IDE’s that can be used to start development but eclipse is the most recommended to do so. You can download Eclipse using this link. Continue reading “Getting started development on android with eclipse”

Error handling in PHP with Error logger working

Error handling in PHP with Error logger working

Logging errors in php is easy, cool and helpful when it comes to test the site for errors as I explained it in my earlier post Logging errors to file in PHP but only till the site is at developer’s end and you working on it. Once you take the site live its just not good anymore. Once you take it on the production end, you cannot show the errors to the user or in case if its even 100% error free you will find that 1 in a 100 person who likes to messup with the sites. Being a programmer you gotta be ready for it. This is the place where comes error handling into play.

Here is a simple script. Just place these two functions in a file and include it at the right place. Probably including from the point onward from where you expect and error would be just perfect.

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 
// Define a custom error handler function userErrorHandler($errno, $errstr, $errfile = '', $errline = 0, $errcontext = array()) { // Getting error type $errorType = array ( E_ERROR => 'ERROR', E_WARNING => 'WARNING', E_PARSE => 'PARSING ERROR', E_NOTICE => 'NOTICE', E_CORE_ERROR => 'CORE ERROR', E_CORE_WARNING => 'CORE WARNING', E_COMPILE_ERROR => 'COMPILE ERROR', E_COMPILE_WARNING => 'COMPILE WARNING', E_USER_ERROR => 'USER ERROR', E_USER_WARNING => 'USER WARNING', E_USER_NOTICE => 'USER NOTICE', E_STRICT => 'STRICT NOTICE', E_RECOVERABLE_ERROR => 'RECOVERABLE ERROR' );   if (array_key_exists($errno, $errorType)) { $err = $errorType[$errno]; } else { $err = 'CAUGHT EXCEPTION'; }   // Getting the error log file from php.ini $file = ini_get('error_log');   // Creating the error log script, same as normal logger would do $error_string = "[" . date("d-M-Y H:i:s", $_SERVER['REQUEST_TIME']) . '] PHP ' . $err . '::' . $errstr . " in " . $_SERVER['SCRIPT_FILENAME'] . " on line " . $errline . "\r\n";   // Logging error to a certain file error_log($error_string, 3, $file);   // Check if the error code is not included in error_reporting if (!(error_reporting() &amp; $errno)) { return; }   // Restore default handlers to prevent errors in errors restore_error_handler();   if (function_exists('restore_exception_handler')) { restore_exception_handler(); }   // Load error page require('_errors/error.php'); exit(); } set_error_handler('userErrorHandler');   // Define a custom handler for uncaught exceptions if (function_exists('set_exception_handler')) { function userExceptionHandler($exception) { // Restore default handlers to prevent errors in errors restore_error_handler(); if (function_exists('restore_exception_handler')) { restore_exception_handler(); }   // Load error page require('error.php'); exit(); } set_exception_handler('userExceptionHandler'); }

Note: Once you start error handling in real time error logging stops. To overcome this a short code is included inside the function that uses PHP’s error_log function to log errors. So if you have a specifc error log file, just point it towards that.

Good luck!!!

Google’s April Fools’ Day Jokes

Since I found out the Google’s easter eggs like the Google gravity and do a barrel roll, I am always on the hunt to find out and reveal all such tricks and fun stuff that google has and is waiting out to be shown to people. In this approach I already have come up with three such lists before this one containing all the fun stuff that I found by now.

Now here is something different from my earlier lists to reveal more of google. In 2012, Google humor was out in full swing for April Fool’s Day, flooding its products with jokes and pranks.