K&R C Program Exercise 1-14

K and R solutions to print a histogram of the frequencies of different characters in its input. 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. 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
#include

#define HISTLEN 15 /*max length of histogram */
#define CHARLENGTH 128 /*max different characters */

/* print horizontal histogram freq. of different characters */
main()
{
int c,i;
int len; /*length of each bar */
int maxvalue; /*maximum value for cc[] */
int cc[CHARLENGTH]; /*character counters*/

for(i=0;imaxvalue)
maxvalue=cc[i];
for(i=1;i0) {
if((len = cc[i]*HISTLEN/maxvalue)<=0)
len=1;
}
else
len=0;
while(len>0)
{
putchar(*);
--len;
}
putchar('n');
}
}
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!

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

K&R C Program Exercise 1-13

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. K and R solution to print a histogram of the lengths of words in its input. 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>

#define MAXLN 10

int main(void)
{
int c;
int inspace = 0;
long lengtharr[MAXLN + 1];
int wordlen = 0;

int firstletter = 1;
long value = 0;
long maxval = 0;
int index = 0;
int done = 0;

for(index = 0; index <= MAXLN; index++)
{
lengtharr[index] = 0;
}

while(done == 0)
{
c = getchar();

if(c == ' ' || c == 't' || c == 'n' || c == EOF)
{
if(inspace == 0)
{
firstletter = 0;
inspace = 1;

if(wordlen <= MAXLN)
{
if(wordlen > 0)
{
value = ++lengtharr[wordlen - 1];
if(value > maxval)
{
maxval = value;
}
}
}
else
{
value = ++lengtharr[MAXLN];
if(value > maxval)
{
maxval = value;
}
}
}
if(c == EOF)
{
done = 1;
}
}
else
{
if(inspace == 1 || firstletter == 1)
{
wordlen = 0;
firstletter = 0;
inspace = 0;
}
++wordlen;
}
}

for(value = maxval; value > 0; value--)
{
printf("%4d | ", value);
for(index = 0; index <= MAXLN; index++)
{
if(lengtharr[index] >= value)
{
printf("* ");
}
else
{
printf(" ");
}
}
printf("n");
}
printf(" +");
for(index = 0; index <= MAXLN; index++)
{
printf("---");
}
printf("n ");
for(index = 0; index < MAXLN; index++)
{
printf("%2d ", index + 1);
}
printf(">%dn", MAXLN);

return 0;
}
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!


List of C Programs
(c) www.c-program-example.com

K&R C Program Exercise 1-12

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. C Program that prints its input one word per line.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(void)
{
int ch;
int flag;

flag = 0;
while((ch = getchar()) != EOF)
{
if(ch == ' ' || ch == 't' || ch == 'n')
{
if(flag == 0)
{
flag = 1;
putchar('n');
}

}
else
{
flag = 0;
putchar(ch);
}
}
return 0;
}
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

K&R C Program Exercise 1-10

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. C Program to Replace each tabs by ‘t’, backspace by ‘b’, and each bakslash by ‘\’.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>

#define BACK_SLASH '\'

int main(void)
{
int c;

while((c = getchar()) != EOF)
{
switch(c)
{
case 'b':
putchar(BACK_SLASH);
putchar('b');
break;
case 't':
putchar(BACK_SLASH);
putchar('t');
break;
case BACK_SLASH:
putchar(BACK_SLASH);
putchar(BACK_SLASH);
break;
default:
putchar(c);
break;
}
}
return 0;
}
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

K&R C Program Exercise 1-09

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. C Program to replacing each string of one or more blanks by a single blank.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(void)
{
int ch;
while ((ch = getchar()) != EOF) {
if (ch == ' ') {
putchar(ch);
while((ch = getchar()) == ' ' && ch != EOF)
;
}
if (ch == EOF)
break;

putchar(ch);
}
return 0;
}
Read more Similar C Programs
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!

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

K&R C Program Exercise 1-08

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. C Program to count blanks, tabs, and newlines. 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(void)
{
int bl, tb, nl;
int c;
int done = 0;
int lastc = 0;

bl = 0;
tb = 0;
nl = 0;

while(done == 0)
{
c = getchar();

if(c == ' ')
++bl;

if(c == 't')
++tb;

if(c == 'n')
++nl;

if(c == EOF)
{
if(lastc != 'n')
{
++nl;
}
done = 1;
}
lastc = c;
}

printf("Blanks: %dnTabs: %dnLines: %dn", bl, tb, nl);
return 0;
}
Read more Similar C Programs
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!

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

K&R C Program Exercise 1-07

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. C program to print the value of EOF.Read more about C Programming Language .
C program to print the value of EOF .

/***********************************************************
* 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(void)
{
printf("The value of EOF is %dnn", EOF);

return 0;
}
Read more Similar C Programs
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!

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

K&R C Program Exercise 1-06

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. C Program to Verify that the expression getchar() != EOF is 0 or 1. The program reads the charecters from the standard input and return 1, while getchar has a charecter to read it. When the program encounters the end of file,then it prints 0.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(void)
{
printf("Press a key. ENTER would be nice :-)nn");
printf("The expression getchar() != EOF evaluates to %dn", getchar() != EOF);
return 0;
}
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

K&R C Programs Exercise 1-05

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. C program to print the Temperature table in reverse order, that is, from 300 degrees to 0 using 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>

/* print Fahrenheit-Celsius table */
int
main()
{
int fahr;

for (fahr = 300; fahr >= 0; fahr = fahr - 20)
printf("%3d %6.1fn", fahr, (5.0/9.0)*(fahr-32));

return 0;
}
Read more Similar C Programs
Number System

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

K&R C Program Exercise 1-03

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. C program to print the corresponding Fahrenheit to Celcius table. print Fahrenheit-celcius table for fahrenheit=0,20…….300;floating-point version. 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(void)
{
float fahr, celsius;
int lower, upper, step;

lower = 0;
upper = 300;
step = 20;

printf("F Cnn");
fahr = lower;
while(fahr <= upper)
{
celsius = (5.0 / 9.0) * (fahr - 32.0);
printf("%3.0f %6.1fn", fahr, celsius);
fahr = fahr + step;
}
return 0;
}
Read more Similar C Programs
Number System

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