POLYNOMIALS (Using Linked List) |
Polynomial: E.g.: 3x5 - 2x3 + x2 + 4 The important information about the polynomial is contained in the coefficients and exponents of x; the variable x itself is just a place holder (a dummy variable). We can think of a polynomial as a sum of terms, each of which consists of a coefficient and an exponent. It can be represented as a list of pairs of coefficients and exponents. A linked list is preferable to a contiguous list for representing a polynomial because we may not know the bound on the degree, or only a few non-zero terms may appear. Functionality Implemented in this Program:
|
C Language Code: |
POLYNOM.H |
// DSTC -- POLYNOM.H -- polynomial header file .. //#include "assert.h" typedef struct polynominal typedef struct polynominallist poly *createpoly(void) void addterm(poly *p,float c,int e) poly *addpoly(poly *p1, poly *p2) while(t1 && t2) while (t1) while (t2) return(p3); // prints the polynomial void printpoly(poly *p) temp = temp->next ; } void killpoly(poly *p) |
POLYNOM.CPP |
#include <stdio.h> main() clrscr() ; printf("\n Enter the 1st Term of Poly in Coeff,Exponent form:" ); addterm(p,c,e) ; printf("\n Enter the 2nd Term of Poly in Coeff,Exponent form:" ); addterm(p,c,e) ;
printf("\n Enter the 3rd Term of Poly in Coeff,Exponent form:") ; addterm(p,c,e) ; printf("\n Print Polynomial ...\n") ; printpoly(p); printf("\n Enter the 1st Term of Poly in Coeff,Exponent form:" ); addterm(p1,c,e) ; printf("\n Enter the 2nd Term of Poly in Coeff,Exponent form:" ); res=addpoly(p,p1) ; } |
We are trying to contribute to the net what ever Technical knowledge. I Believe that knowledge increases by spreading and sharing with others.
Tuesday, January 30, 2024
Arrays - 2D Array/Matrix - DSTC using C Language (Source Code Implemented)
Arrays - 2D Array/Matrix | ||||||||||||||||||||||||||||||
Two-dimensional arrays are a little more complicated to use than one-dimensional ones. Here data is stored in the form of ROWS and COLUMNS which are accessed with the help of SUBSCRIPT number.
The following table illustrates how the subscripts are specified for this array, which has five (5) rows and four (4) columns.
| ||||||||||||||||||||||||||||||
C Language Code: | ||||||||||||||||||||||||||||||
MULTIARR.H | ||||||||||||||||||||||||||||||
// DSTC ------- MULTIARR.H #include "assert.h" typedef struct MultiDimentionArray matrix *makemat(int nr,int nc) void inputmat(matrix *m,int val, int r, int c) int inputmat(matrix *m, int r, int c) void printmat(matrix *m)
for(j=0;j < m->maxc ; j++) void subtract2mat(matrix *m1,matrix *m2,matrix *res) // precondion for matrix Multiplication is matrix *multiplymat(matrix *m1, matrix *m2) for(i=0;i < r->maxr;i++) | ||||||||||||||||||||||||||||||
MULTIARR.CPP | ||||||||||||||||||||||||||||||
// DSTC ------- MULTIARR.CPP (including MULTIARR.H header file) #include <stdio.h> main() int i,j,v ,r,c; printf("\n Enter the 1 Matrix's Dimentions r,c"); m = makemat(r,c); printf("\n Enter the 2 Matrix's Dimentions r,c"); Get Paid by Reading Ads on your Mobiles res = makemat(r,c) ; printf(" = \n" ); |
Arrays - One Dimensional - DSTC using C Language (Source Code Implemented)
Arrays - One Dimensional
|
Arrays have 2 basic operations i.e. extraction and storing values.
|
C Language Code: |
ARRAY1D.H |
#include "assert.h" intarr *makearray(int n) void input(intarr *a1,int val, int pos) int get(intarr *a1,int pos) void printarray(intarr *a1,int posupto) //DISPLAYS THE ARRAY BEFORE SORTING printf("\n"); void sortarray(intarr *a1) for(i=0;i<a1->size-1;+i++) } |
ARRAY1D.CPP |
#include <stdio.h> void main() sortarray(a1) ; |
Rational Numbers (Abstract Data Type) - DSTC using C Language
Rational Numbers (Abstract Data Type) |
Consider the ADT Rational, which is a Mathematical concept of a rational number. A rational number is a number that can be expressed as the quotient of two integers. Operations to be performed for implemented Rational numbers are:
|
C Language Code: |
RATIONAL.H |
typedef struct rational rat *makerat(int a,int b) rat *sumrat(rat *x, rat *y) void killrat(rat *n) void printrat(rat *n) rat *reducerat(rat *r) for(;i>1;i--) return(t);
rat *subtractrat(rat *x, rat *y) Get Paid by Reading Ads on your Mobiles rat *multiplyrat(rat *x, rat *y) rat *dividerat(rat *x, rat *y) void ratequal(rat *x, rat *y) } |
RATIONAL.CPP |
#include <stdio.h> void main() printf("\n Enter 2st num and denomentor(n/d):"); // SUM OF Rational nos. printf("\n Display Two Rational No.s sum "); //********* SUBSTRATION OF 2 RATIONAL NOS. q = subtractrat(m,n); printf("\n Display Two Rational No.s Subtraction "); printrat(q) ; killrat(m) ; } |
Tuesday, January 24, 2023
How do I Insert data in SQL Server using ASP .Net
To insert data into a SQL Server database using ASP.NET, you can use the ADO.NET library to establish a connection to the database and execute an INSERT statement. Here is an example of how to do this:
1. Create a new ASP.NET project and add a reference to the System.Data.SqlClient namespace.
2. Create a new method that will handle the insertion of data.
3. In this method, create a new SqlConnection object and set the connection string to the appropriate value for your SQL Server database.
4. Open the connection using the Open() method.
5. Create a new SqlCommand object and set the CommandText property to the INSERT statement you want to execute.
6. Add any necessary parameters to the SqlCommand object using the Parameters.Add() method.
7. Execute the command using the ExecuteNonQuery() method.
8. Close the connection using the Close() method.
Here is an example of how your code might look:
using (SqlConnection con = new SqlConnection("Data Source=myServer;Initial Catalog=myDB;User ID=myUsername;Password=myPassword"))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("INSERT INTO myTable (col1, col2) VALUES (@val1, @val2)", con))
{
cmd.Parameters.AddWithValue("@val1", "some value");
cmd.Parameters.AddWithValue("@val2", 123);
cmd.ExecuteNonQuery();
}
con.Close();
}
How do I retrieve data from SQL Server using ASP .Net
In order to retrieve data from a SQL Server database in an ASP.NET application, you can use ADO.NET, which is a set of classes that provide data access services for the .NET Framework. The most commonly used classes for this purpose are the SqlConnection, SqlCommand, and SqlDataReader classes.
Here is an example of how you can use these classes to retrieve data from a SQL Server database and display it in an ASP.NET page:
Create a new SqlConnection object and set its connection string to the appropriate value for your SQL Server database.
Create a new SqlCommand object and set its CommandText property to the SQL query you want to execute.
Open the SqlConnection.
Execute the query by calling the ExecuteReader method of the SqlCommand object and store the result in a SqlDataReader object.
Iterate through the SqlDataReader object and retrieve the data you need.
Close the SqlConnection and SqlDataReader.
Here is an example of the above steps
Sample Code:
using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", con))
{
con.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
// Retrieve data from the reader
string name = reader["Name"].ToString();
string city = reader["City"].ToString();
// Do something with the data
}
}
con.Close();
}
}
It's also important to consider that this is just a simple example, and in production applications, you should handle exceptions, use parameters to avoid SQL injection, and dispose objects properly.
Thursday, December 3, 2020
How to Shrink SQL Server Database Log File Size using DBCC Command
How to Shrink SQL Server Database Log File Size using DBCC Command
you must take a full backup of your database before executing the following:
ALTER DATABASE <YOUR DATABASE NAME>
SET RECOVERY SIMPLE
GO
DBCC SHRINKFILE (<YOUR DATABASE LOG FILE NAME>, TARGET SIZE IN MB)
GO
ALTER DATABASE <YOUR DATABASE NAME>
SET RECOVERY FULL