K&R C Program Exercise 1-01(b)

K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Run the “hello, world” program on your system. Experiment with leaving out parts of the program to see what error messages you get. 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()
{
printf("hello, worln")
}


/*Output: The semicolon (;) is missing after printf(). The compiler should recognize that the semicolon is missing and print the appropriate message:
1-1b.c: In function 'main':
1-1b.c:8:1: error: expected ';' before '}' token*/
Read more Similar C Programs
C Basic

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!

(c) www.c-program-example.com

C Program to implement Warshall’s Algorithm

Data structures using C, Here we solve the Warshall’s algorithm using C Programming Language. Warshall’s algorithm enables to compute the transitive closure of the adjacency matrix of any digraph.

/***********************************************************
* 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<math.h>
int max(int,int);
void warshal(int p[10][10],int n)
{
int i,j,k;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
p[i][j]=max(p[i][j],p[i][k]&&p[k][j]);
}
int max(int a,int b)
{ ;
if(a>b)
return(a);
else
return(b);
}
void main()
{
int p[10][10]={0},n,e,u,v,i,j;
clrscr();
printf("n Enter the number of vertices:");
scanf("%d",&n);
printf("n Enter the number of edges:");
scanf("%d",&e);
for(i=1;i<=e;i++)
{
printf("n Enter the end vertices of edge %d:",i);
scanf("%d%d",&u,&v);
p[u][v]=1;
}
printf("n Matrix of input data: n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%dt",p[i][j]);
printf("n");
}
warshal(p,n);
printf("n Transitive closure: n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%dt",p[i][j]);
printf("n");
}
getch();
}
Read more Similar C Programs
Data Structures

Learn C Programming

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!

(c) www.c-program-example.com

C Program to implement Floyd’s Algorithm

Data structures using C, Here we solve the Floyd’s algorithm using C Programming Language. Floyd’s algorithm uses to find the least-expensive paths between all the vertices in a Graph.

/***********************************************************
* 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 min(int,int);
void floyds(int p[10][10],int n)
{
int i,j,k;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i==j)
p[i][j]=0;
else
p[i][j]=min(p[i][j],p[i][k]+p[k][j]);
}
int min(int a,int b)
{
if(a<b)
return(a);
else
return(b);
}
void main()
{
int p[10][10],w,n,e,u,v,i,j;;
clrscr();
printf("n Enter the number of vertices:");
scanf("%d",&n);
printf("n Enter the number of edges:n");
scanf("%d",&e);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
p[i][j]=999;
}
for(i=1;i<=e;i++)
{
printf("n Enter the end vertices of edge%d with its weight n",i);
scanf("%d%d%d",&u,&v,&w);
p[u][v]=w;
}
printf("n Matrix of input data:n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%d t",p[i][j]);
printf("n");
}
floyds(p,n);
printf("n Transitive closure:n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%d t",p[i][j]);
printf("n");
}
printf("n The shortest paths are:n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(i!=j)
printf("n <%d,%d>=%d",i,j,p[i][j]);
}
getch();
}
Read more Similar C Programs
Data Structures

Learn C Programming

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!

(c) www.c-program-example.com

C Program to solve N Queen’s problem

N Queen’s problem is the puzzle. Placing chess queens on a chessboard, so thatNo two queens attack each other. Here we use the Brute-Force method to solve the problem.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<math.h>
int a[30],count=0;
int place(int pos)
{
int i;
for(i=1;i<pos;i++)
{
if((a[i]==a[pos])||((abs(a[i]-a[pos])==abs(i-pos))))
return 0;
}
return 1;
}
void print_sol(int n)
{
int i,j;
count++;
printf("nnSolution #%d:n",count);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(a[i]==j)
printf("Qt");
else
printf("*t");
}
printf("n");
}
}
void queen(int n)
{
int k=1;
a[k]=0;
while(k!=0)
{
a[k]=a[k]+1;
while((a[k]<=n)&&!place(k))
a[k]++;
if(a[k]<=n)
{
if(k==n)
print_sol(n);
else
{
k++;
a[k]=0;
}
}
else
k--;
}
}
void main()
{
int i,n;
clrscr();
printf("Enter the number of Queensn");
scanf("%d",&n);
queen(n);
printf("nTotal solutions=%d",count);
getch();
}
Read more Similar C Programs
Data Structures

Learn C Programming

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!

(c) www.c-program-example.com

C program to cyclically permute the elements of an array.

Example programs to solve the problems of Arrays in C. In This program we, cyclically permute the array elements i.e. arr[0] becomes arr[1], arr[1] becomes arr[2]…so ..on. 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>

void main ()
{
int i,n,number[30];
printf("Enter the value of the n = ");
scanf ("%d", &n);
printf ("Enter the numbersn");
for (i=0; i<n; ++i)
{
scanf ("%d", &number[i]);
}
number[n] = number[0];

for (i=0; i<n; ++i)
{
number[i] = number[i+1];
}
printf ("Cyclically permted numbers are given below n");
for (i=0; i<n; ++i)
printf ("%dn", number[i]);
}
Read more Similar C Programs
Array In C

Simple C Programs

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!

(c) www.c-program-example.com

C program to delete the specified integer from the Array.

Example programs to solve the problems of Arrays in C. In This program we, delete the Array Element, if entered element is in the Array, Else gives the Error message. 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>

void main()
{
int vectx[10];
int i, n, pos, element, found = 0;

printf("Enter how many elementsn");
scanf("%d", &n);

printf("Enter the elementsn");
for(i=0; i<n; i++)
{
scanf("%d", &vectx[i]);
}

printf("Input array elements aren");
for(i=0; i<n; i++)
{
printf("%dn", vectx[i]);
}

printf("Enter the element to be deletedn");
scanf("%d",&element);

for(i=0; i<n; i++)
{
if ( vectx[i] == element)
{
found = 1;
pos = i;
break;
}
}

if (found == 1)
{
for(i=pos; i< n-1; i++)
{
vectx[i] = vectx[i+1];
}

printf("The resultant vector is n");
for(i=0; i<n-1; i++)
{
printf("%dn",vectx[i]);
}
}
else
printf("Element %d is not found in the vectorn", element);

}
Read more Similar C Programs
Array In C

Simple C Programs

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!

(c) www.c-program-example.com

C program to split the array from perticular position

Example programs to solve the problems of Arrays in C. In This program we, cyclically permute the array elements i.e. arr[0] becomes arr[1], arr[1] becomes arr[2]…so ..on. 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>

void main ()
{
int number[30];
int i,n,a,j;

printf ("Enter the value of nn");
scanf ("%d",&n);

printf ("enter the numbersn");
for (i=0; i<n; ++i)
scanf ("%d", &number[i]);

printf ("Enter the position of the element to split the array n");
scanf ("%d",&a);

for (i=0; i<a; ++i)
{
number[n] = number[0];

for (j=0; j<n; ++j)
{
number[j] = number[j+1];
}
}

printf("The resultant array isn");
for (i=0; i<n; ++i)
{
printf ("%dn",number[i]);
}
}
Read more Similar C Programs
Array In C

Simple C Programs

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!

(c) www.c-program-example.com

C program to illustrate the concept of unions

C program to demonstrate unions. unions are like C structures, but every member occupies the same memory region. 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>

void main()
{
union number
{
int n1;
float n2;
};

union number x;

clrscr() ;

printf("Enter the value of n1: ");
scanf("%d", &x.n1);
printf("Value of n1 =%d", x.n1);

printf("nEnter the value of n2: ");
scanf("%d", &x.n2);
printf("Value of n2 = %dn",x.n2);

}
Read more Similar C Programs
Union.

Structures.

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!

(c) www.c-program-example.com

C program to find size-of an array.

Example programs to solve the problems of Arrays in C. In This program we, find the size of the array using sizeof() operator. 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( )
{

int i,num;
printf("nEnter the hoe many elements you want?n");
scanf("%d",&num);

int a[num];
printf("nEnter the %d elements:n",num);
for(i=0;i<num;i++)
{
scanf("%d",&a[i]);
}
printf("Elements in array are:n");
for(i=0;i<num;i++)
{
printf("%dn",a[i]);
}
printf(" The size of the array is: %d Bytes.",(int)sizeof(a));

return 0 ;
}
Read more Similar C Programs
Array In C

Simple C Programs

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!

(c) www.c-program-example.com

C Program to print the pyramid pattern.

C program to print the pyramid pattern. This program prints pyramid of 5 rows using a for loop. 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()
{
int r, c,t=5;

for ( r = 1 ; r <= 5 ; r++ )
{
for ( c = 1 ; c < t ; c++ )
printf(" ");

t--;

for ( c = 1 ; c <= 2*r - 1 ; c++ )
printf("*");

printf("n");
}


return 0;
}
Read more Similar C Programs
Learn C Programming

Simple C Programs

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!

(c) www.c-program-example.com