K&R C Program Exercise 1-16

K and R solutions to Revise the the main routine of the longest-line program so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text. 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 "stdio.h"

#define MAXINLINE 1000 /* maximum input line size */

int getline(char line[], int MAXINLINE);
void copy(char to[], char from[]);

/* print longest input line */
int main(void)
{
int len; /* current line length */
int max; /* maximum length seen so far */
char line[MAXINLINE]; /* current input line */
char longest[MAXINLINE]; /* longest line saved here */

max = 0;

while((len = getline(line, MAXINLINE)) > 0)
{
printf("%d: %s", len, line);

if(len > max)
{
max = len;
copy(longest, line);
}
}
if(max > 0)
{
printf("Longest LINE IN THE PROGRAM is %d characters:n%s", max, longest);
}
printf("n");
return 0;
}

/* getline: read a line into s, return length */
int getline(char s[], int line)
{
int c, i, j;

for(i = 0, j = 0; (c = getchar())!=EOF && c != 'n'; ++i)
{
if(i < line - 1)
{
s[j++] = c;
}
}
if(c == 'n')
{
if(i <= line - 1)
{
s[j++] = c;
}
++i;
}
s[j] = '';
return i;
}

/* copy: copy 'from' into 'to'; assume 'to' is big enough */
void copy(char to[], char from[])
{
int k;

k = 0;
while((to[k] = from[k]) != '')
{
++k;
}
}


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-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-04

K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second edition, 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 Celsius to Fahrenheit table. print Celsius-Fahrenheit table for Celsius=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
***********************************************************/

/*C  program to print the corresponding Celsius to Fahrenheit table. */

#include <stdio.h>

int main(void)
{
 float fahr, celsius;
 int lower, upper, step;

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

 printf("C     Fnn");
 celsius = lower;
 while(celsius <= upper)
 {
  fahr = (9.0/5.0) * celsius + 32.0;
  printf("%3.0f %6.1fn", celsius, fahr);
  celsius = celsius + 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

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 Multiplication table.

C Program to print the multiplication table using while statement. 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 num, i = 1;
printf("n Enter any Number:");
scanf("%d", &num);
printf("Multiplication table of %d: n", num);
while (i <= 10) {
printf("n %d x %d = %d", num, i, num * i);
i++;
}
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

C Program to count the number of occurrences of particular word in a string

C Program that counts the particular word in the given string. For example in the string ” the string is the set of charterers” , Number of occurrences of “the” is:2. 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>

main()

{

 int strln,wordln,i,j,k,flag,count=0;

 char str[200],word[20];

 printf("Enter line of text:n");

 gets(str);

 printf("Enter the word to count:n");

 scanf("%s",word);

 strln=strlen(str);

 wordln=strlen(word);

 for(i=0;i<strln;i++)

 {

  if(str[i]==word[0]&&((str[i-1]==' '||i==0)&&(str[i+wordln]==' '||str[i+wordln]=='')))

  {

   for(flag=0,k=i+1,j=1;j<wordln;j++,k++)

   {

    if(str[k]==word[j])

    {

     flag++;

    }

   }

   if(flag==wordln-1)

   {

    count++;

   }

  }

 }

 printf("Number of occurence of '%s' = %dn",word,count);

}

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

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

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