C Program to solve equations using Jordan elimination method.

Write a C Program to solve equations using Jordan elimination method.
Gauss-Jordan elimination method is used to solve the linear equations. In this method, We find the inverse matrix of the coefficients of equations by elementary row operations. Read more about C Programming Language . and read the C Programming Language (2nd Edition) by K and R.

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
#include<conio.h>
void solution( int a[][], int var );
int main()
{

int a[ 20 ][ 20 ], var, i, j, k, l;
clrcsr();
printf( "nEnter the number of variables:n" );
scanf( "%d", &var );

for ( i = 0;i < var;i++ )
{
printf( "nEnter the equation%d:n", i + 1 );

for ( j = 0;j < var;j++ )
{
printf( "Enter the coefficient of x%d:n", j + 1 );
scanf( "%d", &a[ i ][ j ] );
}

printf( "nEnter the constant:n" );
scanf( "%d", &a[ i ][ n ] );
}

solution( a, var );
return 0;
}



void solution( int a[ 20 ][ 20 ], int var )
{
int k, i, l, j;

for ( k = 0;k < var;k++ )
{
for ( i = 0;i <= var;i++ )
{
l = a[ i ][ k ];

for ( j = 0;j <= var;j++ )
{
if ( i != k )
a[ i ][ j ] = a[ k ][ k ] * a[ i ][ j ] – l * a[ k ][ j ];
}
}
}

printf( "nSolutions:" );

for ( i = 0;i < n;i++ )
{
printf( "nTHE VALUE OF x%d IS %fn", i + 1, ( float ) a[ i ][ n ] / ( float ) a[ i ][ i ] );
}

}
Read more Similar C Programs
Learn C Programming
Recursion
Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C program to replace the sub string with another string.

C Strings:
Write a C program to replace the sub string in a string with another string.
In this program, We replace string with another string, if the entered string is the sub string of main string, otherwise function replace_str returns the original string as it is. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include <stdio.h>
#include <string.h>

char *replace_str(char *str, char *orig, char *rep)
{
static char buffer[4096];
char *p;

if(!(p = strstr(str, orig)))
return str;

strncpy(buffer, str, p-str);
buffer[p-str] = '';

sprintf(buffer+(p-str), "%s%s", rep, p+strlen(orig));

return buffer;
}

int main(void)
{
char str[100],str1[50],str2[50];
printf("Enter a one line string..n");
gets(str);
printf("Enter the sub string to be replaced..n");
gets(str1);
printf("Enter the replacing string....n");
gets(str2);
puts(replace_str(str, str1, str2));

return 0;
}
Read more Similar C Programs
Searching in C

C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to find the position of a sub string.

C Strings:
C Program to find the position of a sub string in a given string.
In this program, We find the position of a sub string where it starts  in the main string. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include <stdio.h>
#include <conio.h>
main()
{
char firststr[30], substr[10];
char *secondstr, *thirdstr;
clrscr();
printf("Enter any string");
scanf("%s",firststr);
printf("Enter sub string");
scanf("%s",substr);
secondstr=firststr;
thirdstr=substr;
i=substr(secondstr, thirdstr);
printf("nn");
if(i!=-1)
printf("The starting location/position of substring in main string: %d", i;
else
printf("String not found");
getch();
}


int substr(secondstr, thirdstr)

{
char *secondstr, *thirdstr;

int j=0,l=0;
static int k;
if(*second==*third)
{
while(i<strlen(third))
{
if(*second==*third)
k=j+1;
else
k+=1;
l++;
}
third++;
second++;
}
second++;
j++;

if(k!=0)
return(k);
else
return(-1);
}
Read more Similar C Programs
Searching in C

C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C program to generate and print prime numbers in a given range.

Write a C program to generate and print prime numbers in a given range. Also print the number of prime numbers.
Prime number is a whole number and greater than 1, which is divisible by one or itself.
Example: 2, 3, 5, 7, 11, 13………… Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>

void main()
{
int M, N, i, j, flag, temp, count = 0;

clrscr();

printf("Enter the value of M and Nn");
scanf("%d %d", &M,&N);

if(N < 2)
{
printf("There are no primes upto %dn", N);
exit(0);
}
printf("Prime numbers aren");
temp = M;

if ( M % 2 == 0)
{
M++;
}
for (i=M; i<=N; i=i+2)
{
flag = 0;

for (j=2; j<=i/2; j++)
{
if( (i%j) == 0)
{
flag = 1;
break;
}
}
if(flag == 0)
{
printf("%dn",i);
count++;
}
}
printf("Number of primes between %d and %d = %dn",temp,N,count);
}



Read more Similar C Programs
Learn C Programming

Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C program To show examples of the strtol function.

C program To show examples of the strtol function.
strtol() function converts the string to the long integer, and strtol() can accept the number in various bases, and converts it into the decimal number or base. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include <stdlib.h>

main()
{
char num[10];

/* Test a valid number */
strcpy(num,"13");

printf("%s(Oct) is %i(Dec)n", num, strtol(num, NULL, 8));
printf("%s(Dec) is %i(Dec)n", num, strtol(num, NULL, 10));
printf("%s(hex) is %i(Dec)n", num, strtol(num, NULL, 16));

puts("----------------------------------");

/* Test a slightly valid number
* Returns the same results as
* above. */
strcpy(num, "13hzcd");

printf("%s(Oct) is %i(Dec)n", num, strtol(num, NULL, 8));
printf("%s(Dec) is %i(Dec)n", num, strtol(num, NULL, 10));
printf("%s(hex) is %i(Dec)n", num, strtol(num, NULL, 16));

puts("----------------------------------");

/* Test an invalid number
* Returns ZERO */
strcpy(num, "hzcd");

printf("%s(Oct) is %i(Dec)n", num, strtol(num, NULL, 8));
printf("%s(Dec) is %i(Dec)n", num, strtol(num, NULL, 10));
printf("%s(hex) is %i(Dec)n", num, strtol(num, NULL, 16));


puts("----------------------------------");

/* Test 0 base.
* This will look at the number
* and decide the base for its self!
*/
strcpy(num, "13");
printf("%s is %i(Dec)n", num, strtol(num, NULL, 0));

strcpy(num, "013");
printf("%s is %i(Dec)n", num, strtol(num, NULL, 0));

strcpy(num, "0x13");
printf("%s is %i(Dec)n", num, strtol(num, NULL, 0));

}
Read more c programs
C Basic
C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to demonstrate sprintf statement.

C Program to demonstrate the ‘sprintf‘ statement. This example is a bit lame as the same effect can be seen with a ‘printf’. But, it does show a string being built and passed into a function. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include <stdio.h>

main()
{
int i=1; /* Define an integer variable. */
char message[80]; /* Text string */

/* format text and put into 'message' this a great
* improvement over using 'strcpy' and 'strcat' to
* build a text string.
*/
sprintf (message, "i is %i", i);
/* I may be stating the obvious but a '' is
* put on the end of the string. */

puts(message); /* Display message */

}

Read more c programs 
C Basic
C Strings
K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

K & R C Programs Exercise 4-13.

K and R C, Solution to Exercise 4-13:
K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language (2nd Edition). You can learn and solve K&R C Programs Exercise.
Write a C Program to reverse the string using the recursive methods.
In this program reverse determines the length of the string and then calls the reverser, which reverses the string s in place. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/
#include<stdio.h>
/* reverse: reverse the string s in place */
void reverse(char s[])
{

void reverser(char s[], int i, int len);
reverser(s,0,strlen(s));
}

/* reverser: reverse string s in place recursive */
void reverser(char s[], int i, int len)
{
int c, j;
j = len - (i + 1);
if(i < j)
{
c = s[i];
s[i] = s[j];
s[j] = c;
reverser(s, ++i, len);
}
}

Read more Similar C Programs
C Basic
C Strings
K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

K & R C Programs Exercise 4-10.

K and R C, Solution to Exercise 4-10:
K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language (2nd Edition). You can learn and solve K&R C Programs Exercise.
C Program to modify the K & R C Programs Exercise 4-5, An alternate organization uses getline to read an entire input line; this makes getch and ungetch unnecessary. revise the caluculater to use this aproach. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
#include<ctype.h>

#define MAXLINE 100
#define NUMBER '0' //SIGNAL THAT A NUMBER WAS FOUND
int getline(char line[], int limit);
int li = 0;
char line[MAXLINE];
/* Getop: get next operator or numeric operand. */
int Getop(char s[])
{
int i;
int c;

if(line[li] == '')
if(getline(line, MAXLINE) == 0)
return EOF;
else li = 0;
/* Skip whitespace */
while((s[0] = c = line[li++]) == ' ' || c == 't')
{
;
}
s[1] = '';

/* Not a number but may contain a unary minus. */
if(!isdigit(c) && c != '.' )
return c;
i = 0;

if(isdigit(c))
while(isdigit(s[++i] = c =line[i++]))
;

if(c == '.')
while(isdigit(s[++i] = c =line[i++]))
;
s[i] = '';
li--;
return NUMBER;
}

Read more Similar C Programs
C Basic
C Strings
K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program which produces its own source code as its output.

Write a c program which produces its own source code as its output.
This C program uses the C File i/o operations like fopen(), fclose(). In this program, We pritn the source code of the program.Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
int main()
{
FILE *fp;
char c;

fp = fopen(__FILE__,"r");

do{

c= getc(fp);

putchar(c);

}
while(c!=EOF);

fclose(fp);

return 0;

}


Read more Similar C Programs
C Basic

C File i/o

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to print ASCII values of all characters.

C Program to print ASCII values of all characters.
ASCII value is the American Standard Code for Information Interchange.
ASCII value is the numerical value, or order, of an character. There are 128 standard ASCII characters, numbered from 0 to 127. Extended ASCII adds another 128 values and goes to 255. The numbers are typically represented in decimal or in hexadecimal. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
#include<conio.h>
int main(){

int i;
clrscr();
for(i=0;i<=255;i++)
printf("ASCII value of
character %c: %dn",i,i);
getch();
return 0;

}
Read more Similar C Programs
Learn C Programming

Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com