The increasing popularity of C is probably due to its many desirable qualities. It is a robust language whose rich set of built-in functions amd operators can be used to write any complex program. The C complier combines the capabilities of an assembly language with the features of the high level language and therefore it is well suited for writing both system software and business packages. In this blog, about 68 examples of C programming are written which is understand to you that how C programming works.
Program : Processing of a Customer List
Telephone number of important customers are recorded as follows:
Full name Telephone number
Joseph Louis Lagrange 869245
Jean Robert Argand 900823
Carl Freidrich Gauss 806788
---------- ---------
----------- ---------
It is desired to prepare a revised alphabetical list with surname (last name) first, followed by a comma and the initials of the first and the middle names. For example,
Argand, J.R
We create a table of strings, each row representing the details of one person, such as first_name, middle_name, last_name, and telephone_number. The columns are interchanged as required and the list is sorted an the last_name.
PROGRAM
# define CUSTOMERS 10
main ( )
{
char first_name [20] [10], second name [20] [10],
surname [20] [10], name [20] [20], telephone [20] [10],
dummy [20] ;
int i, j ;
printf ("Input names and a telephone number \n") ;
printf ("?") ;
for (i = 0; i < CUSTOMER; i++)
{
scanf ("%s %s %s %s", first_name[i],
second_name [i], surname [i], telephone[i]) ;
/* converting full name to surname with initials */
strcpy (name[i], surname [i]) ;
strcat (name[i], ",") ;
dummy [0] = first_name [i] [0] ;
dummy [1] = '\0' ;
strcat (name [i], dummy) ;
strcat (name [i], ".") ;
dummy [0] = second_name [i] [0] ;
dummy [1] = '\0' ;
strcat (name [i], dummy) ;
}
/* Alphabetical ordering of surnames */
for (i = 1; i <= CUSTOMERS - 1; i++)
for (j = 1; j<= CUSTOMERS - i; j++)
if (strcmp (name[j - i], name [j]) > 0)
{
/* Swaping names */
strcpy (dummy, name [j - 1]) ;
strcpy (name [j - 1], name [j]) ;
strcpy (name [j], dummy) ;
/* Swaping telephones numbers */
strcpy (dummy, telephone [j - 1]) ;
strcpy (telephone [j - 1], telephone[j]) ;
strcpy (telephone [j], dummy) ;
}
/* Printing alphabetical list */
printf ("\nCUSTOMERS LIST IN ALPHABETICAL
ORDER \n\n") ;
for (i = 0; i < CUSTOMERS; i++)
printf (" %-20s\t %-10s\n", name [i], telephone[i]);
}
Output: Input names and telephone number
? Gottfreind Wilhelm Leibniz 7115198
Joseph Louis LAGRANGE 869245
Jean Robert Argand 900823
Carl Freidrich Gauss 806788
Simon Denis Poisson 853240
Friedrich Withelm Bessel 719731
Charles Francois Sturm 222031
George Gabriel Srokes 545454
Mohandas Kramachand Gnadhi 362718
Josian Willard Gibbs 123145
CUSTOMERS LIST IN ALPHABETICAL ORDER
Argand,J.R 900823
Bessel,F.W 719731
Gandhi,M.K 362718
Gauss,C.F 806788
Gibbs,J.W 123145
Lagrange,J.L 869245
Leibniz,G.W 711518
Poission,S.D 853240
Strokes,G.G 545454
Strum,C.F 222031
No comments:
Post a Comment