gsm

Mobile Communication System (GSM, GPRS, EDGE, UMTS, HSPA, HSPA+ , LTE, LTE Advance )


Mobile Communication System

Mobile Communication System is a radio signal based communication system or network that cover a specific area with a base station and stations are connected with wire, fiber or it can be wireless and all the base station and other station is control through switching center. In this communication system, covered area is similar like a cell, that’s why sometime it called Cellular Network also. Each of the cell or base station give access for mobile services. Base stations are communicate mobile devices with Radio transmission dishes. For communicate one mobile device with other mobile device in network covered are of a cell, All the mobile devices are first connect with the base station of the cell and base station send signal to the switching center then the switching center connect the another mobile device through the base station of device location.

There are many different kinds of Mobile communication System:

  1. Nordic Mobile Telephone (NMT)
  2. Advanced Mobile Phone System (AMPS)
  3. Total Access Communication Systems (TACS)
  4. Nordic Mobile Telephony (NMT)
  5. American Digital Cellular (ADC)
  6. Global System for Mobile Communication (GSM)
  7. Digital Cellular System (DCS) 1800
  8. Japanese Personal Digital Cellular (PDC)
  9. Personal Communications Service (PCS) 1900 – Canada
  10. Personal Communications Service (PCS) – USA

Among the all over the world, GSM (Global System for Mobile) is most popular mobile communication system. GSM is second generation (2G) Standard Communication System for mobile network. It is basically based on on the time division multiple access (TDMA) system technology. With this technology , GSM user can use digital signaling and voice channels. Using TDMA, a narrow band that is 30 kHz wide and 6.7 milliseconds long is split time-wise into three time slots. GSM used different kinds of frequency carrier band like, 900 MHz band for normal GSM communication, 1800 MHz for giver the network user swelling number support and 1900Mhz for better down-link. GSM is now one of the growing fastest wireless technology all over the world. GSM technology is now third generation (3G) standard legacy network. Technological evaluation of GSM is remarkable.

gsm

General Packet Radio Service (GPRS), Enhanced Data for GSM Evolution (EDGE), Universal Mobile Telecommunication System (UMTS), High Speed Packet Access (HSPA),  Long Term Evolution (LTE), Al those technology make GSM so popular. There are many advance feature of GSM like Clear voice quality, international rooming, Spectral flexibility, Tight security, Data support, Subscriber Identity Module (SIM) cards.

For allowing multiple user, all the Mobile communication system use some method of technology for sharing the system concurrently. There are three method of technology is used commonly and they are :-

  1. FDM Frequency Division Multiplexing
  2. TDMA Time Division Multiple Access
  3. CDMA Code Division Multiple Access

Frequency Division Multiplexing: In FDM technology, available frequency are divided into many channels. Each and every communication use a channel for communicate. If in any area, all the channels are busy then this technology not allow other user for make a call. FDM operates much like the channel button on your television set. The AMPS and NAMPS mobile telephone systems utilize FDM.

Time Division Multiple AccessIn TDMA system, Encoded voice signal is converted into digital and send the data via RF(radio frequency). In time division multiple Access technology, frequency are send in different length of wave and it change in every 2 second slot and each 30khz frequency are divided into three time slot. D-AMPS, D-AMPS 1900, GSM, PCS and iDEN systems are all use TDMA technology.

Code Division Multiple Access :In a CDMA system, voice is encoded in digital signal and divided into small packets. These packets are tagged with “codes.” and they are mixed with all of the other packets of traffic in the local CDMA network. when they are routed towards their destination. The receiving system only accepts the packets with the codes destined for it.this is one of the smartest technology for mobile communication.

Mobile Communication System Architecture:

2345

The Switching System : The switching system is very operative system in which many crucial operation are conducted. There are five database from SS and they are : HLR, MSC, VLR, AuC and EIR.

HLR : Home Location Register

MSC : Mobile Service Switching Center

VLR : Visitor Location Register

AUC : Authentication Center

EIR : Equipment Identity Register

BSS:  Base Stataion Subsystem

BTS: The Base Station Center

There are some related system of Mobile comunication System and they are :

  • WLANs
  • Mobile IP network
  • Access points
  • Ad hoc
  • Sensor networks
  • Mobile Computing Systems Network

Fundamental Concepts in Programming Languages : 2


2. Basic concepts:

2.1. Assignment commands

One of the characteristic features of computers is that they have a store into which it is possible to put information and from which it can subsequently be recovered. Furthermore the act of inserting an item into the store erases whatever was in that particular area of the store before—in other words the process is one of overwriting. This leads to the assignment command which is a prominent feature of most programming languages.

The simplest forms of assignments such as

ð  x := 3        

ð  x := y + 1

ð  x := x + 1

Lend themselves to very simple explications. ‘Set x equal to 3’, ‘Set x to be the value of y plus 1’ or ‘Add one to x’. But this simplicity is deceptive; the examples are themselves special cases of a more general form and the first explications which come to mind will not generalize satisfactorily. This situation crops up over and over again in the exploration of a new field; it is important to resist the temptation to start with a confusingly simple example.

The following assignment commands show this danger.

                                  i := a > b    j,k                                                               ( .See note 1)

                             A[i] := A[a > b → j,k]     

A[a > b j, k] := A[i]

                 a > b j, k := I                                                                                 ( .See note 2)

All these commands are legal in CPL (and all but the last, apart from minor syntactic alterations, in ALGOL also). They show an increasing complexity of the expressions written on the left of the assignment. We are tempted to write them all in the general form

                                                                         1 := 2

where 1 and  ἐ2 stand for expressions, and to try as an explication something like ‘evaluate the two expressions and then do the assignment’. But this clearly will not do, as the meaning of an expression (and a name or identifier is only a simple case of an expression) on the left of an assignment is clearly different from its meaning on the right. Roughly speaking an expression on the left stands for an ‘address’ and one on the right for a ‘value’ which will be stored there. We shall therefore accept this view and say that there are two values associated with an expression or identifier. In order to avoid the overtones which go with the word ‘address’ we shall give these two values the neutral names: L-value for the address-like object appropriate on the left of an assignment, and R-value for the contents-like object appropriate for the right.

 

2.2. L-values and R-values:

An L-value represents an area of the store of the computer. We call this a location rather than an address in order to avoid confusion with the normal store-addressing mechanism of the computer. There is no reason why a location should be exactly one machine-word in size— the objects discussed in programming languages may be, like complex or multiple precision numbers, more than one word long, or, like characters, less. Some locations are addressable (in which case their numerical machine address may be a good representation) but some are not. Before we can decide what sort of representation a general, non-addressable location should have, we should consider what properties we require of it.

The two essential features of a location are that it has a content—i.e. an associated R-value—and that it is in general possible to change this content by a suitable updating operation. These two operations are sufficient to characterise a general location which are consequently sometimes known as ‘Load-Update Pairs’ or LUPs. They will be discussed

again in (Section 4.1)

2.3. Definitions

In CPL a programmer can introduce a new quantity and give it a value by an initialized definition such as

               let p = 3.5                    (In ALGOL this would be done by real p; p := 3.5;).

This introduces a new use of the name p (ALGOL uses the term ‘identifier’ instead of name), and the best way of looking at this is that the activation of the definition causes a new location not previously used to be set up as the L-value of p and that the R-value 3.5 is then assigned to this location. The relationship between a name and its L-value cannot be altered by assignment, and it is this fact which makes the L-value important. However in both ALGOL and CPL one name can have several different L-values in different parts of the program. It is the concept of scope (sometimes called lexicographical scope) which is controlled by the block structure which allows us to determine at any point which L-value is relevant. In CPL, but not in ALGOL, it is also possible to have several names with the same L-value. This is done by using a special form of definition:

Let, q ͠= P

which has the effect of giving the name of the same L-value as p (which must already exist). This feature is generally used when the right side of the definition is a more complicated expression than a simple name. Thus if M is a matrix, the definition

let x ͠=  M[2,2]

gives x the same L-value as one of the elements of the matrix. It is then said to be sharing with M[2,2], and an assignment to x will have the same effect as one to M[2,2]. It is worth noting that the expression on the right of this form of definition is evaluated in the L-mode to get an L-value at the time the definition is obeyed. It is this L-value which is associated with x. Thus if we have

let i = 2

let x ͠=  M[i,i]

i:=3

the L-value of x will remain that of M[2,2]. M[i,i] is an example of an anonymous quantity i.e., an expression rather than a simple name—which has both an L-value and an R-value. There are other expressions, such as a+b, which only have R-values. In both cases the expression has no name as such although it does have either one value or two.

2.4. Names

It is important to be clear about this as a good deal of confusion can be caused by differing uses of the terms. ALGOL 60 uses ‘identifier’ where we have used ‘name’, and reserves the word ‘name’ for a wholly different use concerned with the mode of calling parameters for a procedure. (See Section 3.4.3.) ALGOL X, on the other hand, appears likely to use the word ‘name’ to mean approximately what we should call an L-value, (and hence something which is a location or generalised address). The term reference is also used by several languages to mean (again approximately) an L-value. It seems to me wiser not to make a distinction between the meaning of ‘name’ and that of ‘identifier’ and I shall use them interchangeably. The important feature of a name is that it has no internal structure at any rate in the context in which we are using it as a name. Names are thus atomic objects and the only thing we know about them is that given two names it is always possible to determine whether they are equal (i.e., the same name) or not.

2.5. Numerals

We use theword ‘number’ for the abstract object and ‘numeral’ for its written representation.Thus 24 and XXIV are two different numerals representing the same number. There is often some confusion about the status of numerals in programming languages. One view commonly expressed is that numerals are the ‘names of numbers’ which presumably means that every distinguishable numeral has an appropriate R-value associated with it. This seems

to me an artificial point of view and one which falls foul of Occam’s razor by unnecessarily multiplying the number of entities (in this case names). This is because it overlooks the important fact that numerals in general do have an internal structure and are therefore not atomic in the sense that we said names were in the last section. An interpretation more in keeping with our general approach is to regard numerals as R-value expressions written according to special rules. Thus for example the numeral 253 is a syntactic variant for the expression

2*102 C+ 5 * 10 + 3

while the CPL constant 8 253 is a variant of

2 * 82 + 5* 8 +3

Local rules for special forms of expression can be regarded as a sort of ‘micro-syntax’ and form an important feature of programming languages. The micro-syntax is frequently used in a preliminary ‘pre-processing’ or ‘lexical’ pass of compilers to deal with the recognition of names, numerals, strings, basic symbols (e.g. boldface words in ALGOL) and similarobjects which are represented in the input stream by strings of symbols in spite of beingatomic inside the language.With this interpretation the only numerals which are also names are the single digits and these are, of course, constants with the appropriate R-value.

2.6. Conceptual model

It is sometimes helpful to have a picture showing the relationships between the various objects in the programming language, their representations in the store of a computer and the abstract objects to which they correspond. Figure 1 is an attempt to portray the conceptual model which is being used in this course.

hhh

On the left are some of the components of the programming language. Many of these correspond to either an L-value or an R-value and the correspondence is indicated by an arrow terminating on the value concerned. Both L-values and R-values are in the idealized store, a location being represented by a box and its contents by a dot inside it. R-values without corresponding L-values are represented by dots without boxes, and R-values which are themselves locations (as, for example, that of a vector) are given arrows which terminate on another box in the idealised store. R-values which correspond to numbers are given arrows which terminate in the right hand part of the diagram which represents the abstract objects with which the program deals. The bottom section of the diagram, which is concerned with vectors and vector elements will be more easily understood after reading the section on compound data structures. (Section 3.7.)

Fundamental Concepts in Programming Languages : 1


Abstract. This paper forms the substance of a course of lectures given at the International Summer School in Computer Programming at Copenhagen in August, 1967. The lectures were originally given from notes and the paper was written after the course was finished. In spite of this, and only partly because of the shortage of time, the paper still retains many of the shortcomings of a lecture course. The chief of these are an uncertainty of aim—it is never quite clear what sort of audience there will be for such lectures—and an associated switching from formal to informal modes of presentation which may well be less acceptable in print than it is natural in the lecture room. For these (and other) faults, I apologies to the reader. There are numerous references throughout the course to CPL [1–3]. This is a programming language which has been under development since 1962 at Cambridge and London and Oxford. It has served as a vehicle for research into both programming languages and the design of compilers. Partial implementations exist at Cambridge and London. The language is still evolving so that there is no definitive manual available yet. We hope to reach another resting point in its evolution quite soon and to produce a compiler and reference manuals for this version. The compiler will probably be written in such a way that it is relatively easy to transfer it to another machine, and in the first instance we hope to establish it on three or four machines more or less at the same time. The lack of a precise formulation for CPL should not cause much difficulty in this course, as we are primarily concerned with the ideas and concepts involved rather than with their precise representation in a programming language.

 

 

 

 

Preliminaries:

1.1. Introduction

Any discussion on the foundations of computing runs into severe problems right at the start. The difficulty is that although we all use words such as ‘name’, ‘value’, ‘program’, ‘expression’ or ‘command’ which we think we understand, it often turns out on closer investigation that in point of fact we all mean different things by these words, so that communication is at best precarious. These misunderstandings arise in at least two ways. The first is straightforwardly incorrect or muddled thinking. An investigation of the meanings of these basic terms is undoubtedly an exercise in mathematical logic and neither to the taste nor within the field of competence of many people who work on programming languages. As a result the practice and development of programming languages has outrun our ability to fit them into a secure mathematical framework so that they have to be described in ad hoc ways. Because these start from various points they often use conflicting and sometimes also inconsistent interpretations of the same basic terms.

 

A second and more subtle reason for misunderstandings is the existence of profound differences in philosophical outlook between mathematicians. This is not the place to discuss this issue at length, nor am I the right person to do it. I have found, however, that these differences affect both the motivation and the methodology of any investigation like this to such an extent as to make it virtually incomprehensible without some preliminary warning. In the rest of the section, therefore, I shall try to outline my position and describe the way in which I think the mathematical problems of programming languages should be tackled. Readers who are not interested can safely skip to Section 2.

 

1.2. Philosophical considerations

The important philosophical difference is between those mathematicians who will not allow the existence of an object until they have a construction rule for it, and those who admit the existence of a wider range of objects including some for which there are no construction rules. (The precise definition of these terms is of no importance here as the difference is really one of psychological approach and survives any minor tinkering.) This may not seem to be a very large difference, but it does lead to a completely different outlook and approach to the methods of attacking the problems of programming languages.

 

The advantages of rigor lie, not surprisingly, almost wholly with those who require construction rules. Owing to the care they take not to introduce undefined terms, the better examples of the work of this school are models of exact mathematical reasoning. Unfortunately, but also not surprisingly, their emphasis on construction rules leads them to an intense concern for the way in which things are written—i.e., for their representation, generally as strings of symbols on paper—and this in turn seems to lead to a preoccupation with the problems of syntax. By now the connection with programming languages as we know them has become tenuous, and it generally becomes more so as they get deeper into syntactical questions. Faced with the situation as it exists today, where there is a generally known method of describing a certain class of grammars (known as BNF or context-free), the first instinct of these mathematicians seems to be to investigate the limits of BNF—what can you express in BNF even at the cost of very cumbersome and artificial constructions? This may be a question of some mathematical interest (whatever that means), but it has very little relevance to programming languages where it is more important to discover better methods of describing the syntax than BNF (which is already both inconvenient and inadequate for ALGOL) than it is to examine the possible limits of what we already know to be an unsatisfactory technique. This is probably an unfair criticism, for, as will become clear later, I am not only temperamentally a Platonist and prone to talking about abstracts if I think they throw light on a discussion, but I also regard syntactical problems as essentially irrelevant to programming languages at their present stage of development. In a rough and ready sort of way it seems to me fair to think of the semantics as being what we want to say and the syntax as how we have to say it. In these terms the urgent task in programming languages is to explore the field of semantic possibilities. When we have discovered the main outlines and the principal peaks we can set about devising a suitably neat and satisfactory notation for them, and this is the moment for syntactic questions.

 

 

But first we must try to get a better understanding of the processes of computing and their description in programming languages. In computing we have what I believe to be a new field of mathematics which is at least as important as that opened up by the discovery (or should it be invention?) of calculus. We are still intellectually at the stage that calculus was at when it was called the ‘Method of Fluxions’ and everyone was arguing about how big a differential was. We need to develop our insight into computing processes and to recognise and isolate the central concepts—things analogous to the concepts of continuity and convergence in analysis. To do this we must become familiar with them and give them names even before we are really satisfied that we have described them precisely. If we attempt to formalise our ideas before we have really sorted out the important concepts the result, though possibly rigorous, is of very little value—indeed it may well do more harm than good by making it harder to discover the really important concepts. Our motto should be ‘No axiomatisation without insight’.

However, it is equally important to avoid the opposite of perpetual vagueness. My own view is that the best way to do this in a rapidly developing field such as computing, is to be extremely careful in our choice of terms for new concepts. If we use words such as ‘name’, address’, ‘value’ or ‘set’ which already have meanings with complicated associations and overtones either in ordinary usage or in mathematics, we run into the danger that these associations or overtones may influence us unconsciously to misuse our new terms—either in context or meaning. For this reason I think we should try to give a new concept a neutral name at any rate to start with. The number of new concepts required may ultimately be quite large, but most of these will be constructs which can be defined with considerable precision in terms of a much smaller number of more basic ones. This intermediate form of definition should always be made as precise as possible although the rigorous description of the basic concepts in terms of more elementary ideas may not yet be available. Who when defining the eigenvalues of a matrix is concerned with tracing the definition back to Piano’s axioms?

 

Not very much of this will show up in the rest of this course. The reason for this is partly that it is easier, with the aid of hindsight, to preach than to practice what you preach. In part, however, the reason is that my aim is not to give an historical account of how we reached

the present position but to try to convey what the position is. For this reason I have often Preferred a somewhat informal approach even when mere formality would in fact have been easy.

 

 

 

 

 

 

Different kinds of Hidden security Cameras


Today cameras are widely use in the purpose of security. All the cameras names are depends on the purpose of it use. Like hidden cameras, spy cameras or video cameras.These cameras are used for security with trust. There are many kinds of security cameras are available in the market. Some are

    hidden cameras
    spy camera
    spy cameras for home
    hidden spy cameras

  1. Smoke Detector Camera with Microphone: This type of cameras is used for fire security.
  2. Hidden Motion Detector Camera: These Cameras are used for prevent unwanted entry in restricted area. If motion is detected it make alarm automatically.
  3. Motion Detector Camera With Audio :This type cameras are also motion detector but it has extra quality it also detect the audio motion also.
  4. Air Purifier Camera: Sometime Cameras are hidden in air purifier for more safty.
  5. WiFi Camera: Now days Wi-Fi hidden cameras are so popular. Because it need not any wire for transfer it information to monitor. This type of cameras is usually small so it give more facility for hidden.

There many like those exit sign hidden video camera, handbag color hidden camera, hidden book camera, hidden camera in electric socket, hidden neck tie camera.

E.BALAGURUSAMY SOLUTION PROGRAMMING IN ANSI C: CHAPTER-8


8.3 Write a program to extract a portion of a character string and print the extracted string. Assume that m characters are extracted, starting with the nth character.

Answer:

//Write a program to extract a portion of a character string and print the extracted string.
//Assume that m characters are extracted, starting with the nth character.
//Date: 18/03/2010#include
#include
#define MAX 50
void main()
{
   char Str1[MAX];
   int i,m,n,j;
   clrscr();
   printf("Enter A String:--\n");
   scanf("%[^\n]s",Str1);
   printf("\nEnter Number of Characters Which U Wnat to Extract-->\n");
   scanf("%d",&m);
   printf("\nEnter Beginnig Index from Which U Want to Extract-->\n");
   scanf("%d",&n);
   printf("\nExtracted String is:--\n\n");
   for(i=n-1;i

getch();

}

 

 

8.7 A Maruti car dealer maintains a reecord of sales of various vehicles in the following

      form:

 

               Vehicle Type                          Month of sales                                   Price

               MARUTI-800                                    02/01                                                   210000

               MARUTI-DX                                    07/01                                                   265000

               GYPSY                                  04/02                                                   315750

               MARUTI-VAN                     08/02                                                   240000

 

     Write a program to read this data into a table of strings and output the details of a

     particular vehicle sold during a specified period. The program should request the user to

     input the vehicle type and the period (starting month, ending month). 

 

Answer:

#include<stdio.h>

#include<conio.h>

#define MAX 10

void main()

{

char Veh[MAX][MAX]={“”};

char Vehicle[MAX];

int St_Mon[MAX],En_Mon[MAX],StMon,EnMon;

long int Price[MAX];

int n,i;

clrscr();

printf(“How Entries U Want to Enter\n”);

scanf(“%d”,&n);

printf(“Enter Vehcle Type,Starting Month, Ending Month & Price:–\n”);

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

{

scanf(“%s”,Veh[i]);

scanf(“%d”,&St_Mon[i]);

scanf(“%d”,&En_Mon[i]);

scanf(“%ld”,&Price[i]);

}

clrscr();

printf(“Vehicle Type       Month of Sales         Price\n”);

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

{

printf(“%s            0%d / 0%d             %ld\n”,Veh[i],St_Mon[i],En_Mon[i],Price[i]);

}

printf(“Enter The Type of Vehicle\n”);

scanf(“%s”,Vehicle);

printf(“Enter the Starting & Ending Month\n”);

scanf(“%d %d”,&StMon,&EnMon);

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

{

if((strcmp(Veh[i],Vehicle)==0))

{

if(St_Mon[i]>=StMon)

{

if(En_Mon[i]<=EnMon)

{

printf(“Vehicle Type  %s is Sold During Period 0%d/0%d\n”,Vehicle,StMon,EnMon);

getch();

exit(0);

}

}

}

}

printf(“Vehicle Type  %s Not Sold During Period 0%d/0%d\n”,Vehicle,StMon,EnMon);

getch();

}

 

 

8.9 Write a program that reads the cost of an item in the form RRRR.PP (where RRRR denotes Rupees and PP denotes Paise) and converts the value to a string of words that express the numeric value in words. For example, if we input 125.75 the ouput should be“ONE HUNDRED TWENTY FIVE AND PAISE SEVENTY FIVE”.

 

Answer:

#include<stdio.h>
#include<conio.h>
void main()
{
   float Cost,Pai,Re,j;
   int Rup,i,R;
   clrscr();
   printf("\nEnter Cost of an ITEM-->\n");
   scanf("%f",&Cost);
   Rup = Cost;
   Pai = (Cost - Rup)*100;
   i=Rup/100;
   switch(i)
   {
               case 1: printf("ONE HUNDRED "); break;
               case 2: printf("TWO HUNDRED "); break;
               case 3: printf("THREE HUNDRED "); break;
               case 4: printf("FOUR HUNDRED "); break;
               case 5: printf("FIVE HUNDRED "); break;
               case 6: printf("SIX HUNDRED "); break;
               case 7: printf("SEVEN HUNDRED "); break;
               case 8: printf("EIGHT HUNDRED "); break;
               case 9: printf("NINE HUNDRED "); break;
   }
   i=Rup%100;
   R=i/10;
   Re=(float)i/10;
   switch(R)
   {
               case 1: printf("TEN"); break;
               case 2: printf("TWENTY "); break;
               case 3: printf("THIRTY "); break;
               case 4: printf("FOURTY "); break;
               case 5: printf("FIFTY "); break;
               case 6: printf("SIXTY "); break;
               case 7: printf("SEVENTY "); break;
               case 8: printf("EIGHTY "); break;
               case 9: printf("NINETY "); break;
   }
   R=(Re-R)*10;
   switch(R)
   {
               case 1: printf("ONE"); break;
               case 2: printf("TWO "); break;
               case 3: printf("THREE "); break;
               case 4: printf("FOUR "); break;
               case 5: printf("FIVE "); break;
               case 6: printf("SIX "); break;
               case 7: printf("SEVEN "); break;
               case 8: printf("EIGHT "); break;
               case 9: printf("NINE "); break;
   }
   printf("AND PAISE ");
   i=Pai/10;
   Re=(float)Pai/10;
   R=(Re-i)*10;
   switch(i)
   {
               case 1: printf("TEN"); break;
               case 2: printf("TWENTY "); break;
               case 3: printf("THIRTY "); break;
               case 4: printf("FOURTY "); break;
               case 5: printf("FIFTY "); break;
               case 6: printf("SIXTY "); break;
               case 7: printf("SEVENTY "); break;
               case 8: printf("EIGHTY "); break;
               case 9: printf("NINETY "); break;
   }
   switch(R)
   {
               case 1: printf("ONE"); break;
               case 2: printf("TWO "); break;
               case 3: printf("THREE "); break;
               case 4: printf("FOUR "); break;
               case 5: printf("FIVE "); break;
               case 6: printf("SIX "); break;
               case 7: printf("SEVEN "); break;
               case 8: printf("EIGHT "); break;
               case 9: printf("NINE "); break;
   }
   getch();
}




8.10 Develop a program that will read and store the details of a list of students in the format

 

   Roll No.                                  Name                          Marks Obtained

………….                                  ………                        ………………..

………….                                  ………                        ………………..

 

And produce the following output lists:

a)      Alphabetical list of names, roll numbers and marks obtained.

b)     List sorted on roll numbers.

c)      List sorted on marks (rank-wise list)

 

 

Answer:

 

#include<stdio.h>

#include<conio.h>

#define MAX 50

void main()

{

char Stu_Name[MAX][MAX]={“”};

//char Stu_Name1[MAX][MAX]={“”};

char Temp[MAX]=””;

int roll_No[MAX],Marks[MAX],n,i,In[MAX],Roll_No1[MAX],Marks1[MAX];

int Temp1,Temp2;

int j;

clrscr();

printf(“How Many Student Name U Want to Enter\n\n”);

scanf(“%d”,&n);

printf(“Enter Roll No. & Students Name & Total Marks:–\n”);

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

{

scanf(“%d”,&Roll_No[i]);

scanf(“%s”,Stu_Name[i]);

scanf(“%d”,&Marks[i]);

}

clrscr();

printf(“Roll No      Name          Marks\n”);

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

{

printf(“%d%s%d\n”,Roll_No[i],Stu_Name[i],Marks[i]);

}

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

{

for(j=0;j<n-i-1;j++)

{

if(strcmp(Stu_Name[j],Stu_Name[j+1])>0)

{

strcpy(Temp,Stu_Name[j]);

strcpy(Stu_Name[j],Stu_Name[j+1]);

strcpy(Stu_Name[j+1],Temp);

Temp1=Roll_No[j];

Roll_No[j]=Roll_No[j+1];

Roll_No[j+1]=Temp1;

Temp2=Marks[j];

Marks[j]=Marks[j+1];

Marks[j+1]=Temp2;

}

}

}

printf(“\nAccording to Student Names:–\n”);

printf(“Roll No      Name          Marks\n”);

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

{

printf(“%d            %s            %d\n”,Roll_No[i],Stu_Name[i],Marks[i]);

}

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

{

for(j=0;j<n-i-1;j++)

{

if(Roll_No[j]>Roll_No[j+1])

{

strcpy(Temp,Stu_Name[j]);

strcpy(Stu_Name[j],Stu_Name[j+1]);

strcpy(Stu_Name[j+1],Temp);

Temp1=Roll_No[j];

Roll_No[j]=Roll_No[j+1];

Roll_No[j+1]=Temp1;

Temp2=Marks[j];

Marks[j]=Marks[j+1];

Marks[j+1]=Temp2;

}

}

}

printf(“\nAccording to Marks:–\n”);

printf(“Roll No      Name          Marks\n”);

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

{

printf(“%d            %s            %d\n”,Roll_No[i],Stu_Name[i],Marks[i]);

}

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

{

for(j=0;j<n-i-1;j++)

{

if(Marks[j]<Marks[j+1])

{

strcpy(Temp,Stu_Name[j]);

strcpy(Stu_Name[j],Stu_Name[j+1]);

strcpy(Stu_Name[j+1],Temp);

Temp1=Roll_No[j];

Roll_No[j]=Roll_No[j+1];

Roll_No[j+1]=Temp1;

Temp2=Marks[j];

Marks[j]=Marks[j+1];

Marks[j+1]=Temp2;

}

}

}

printf(“\nAccording to Roll No:–\n”);

printf(“Roll No      Name          Marks\n”);

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

{

printf(“%d            %s            %d\n”,Roll_No[i],Stu_Name[i],Marks[i]);

}

getch();

}

 

 

8.11 Write a program to read to strings and compare them using the function strcmp() and print a mesaage that the first string is equal, less or greater than the second one.

 

Answer:

#include<stdio.h>

#include<conio.h>

#define MAX 50

void main()

{

char Str1[MAX],Str2[MAX];

 

clrscr();

 

printf(“Enter First String:–\n”);

scanf(“%[^\n]s”,Str1);

 

fflush(stdin);

 

printf(“Enter Second String:–\n”);

scanf(“%[^\n]s”,Str2);

 

if(strcmp(Str1,Str2)==0)

printf(“\nBoth Strings are Equal\n”);

else if(strcmp(Str1,Str2)<0)

printf(“\nFirst String is Less Than\n”);

else

printf(“\nFirst String is Greater Than\n”);

getch();

}

 

 

8.12 Write a program to read a line of text from the keyboard and print out the number of occurrences of a given substring using the function strstr().

Answer:

#include<stdio.h>

#include<conio.h>

 

#define MAX 50

 

void main()

{

char *Str1,*Str2,*Str3;

int i,Len,Len1,Count;

 

clrscr();

 

Count=0;

 

printf(“Enter Text:–\n”);

scanf(“%[^\n]s”,Str1);

 

fflush(stdin);

 

printf(“Enter Substring:–\n”);

scanf(“%[^\n]s”,Str2);

 

Len=strlen(Str1);

Len1=strlen(Str2);

 

strcpy(Str3,Str1);

 

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

{

if((Str3=strstr(Str3,Str2))!=NULL)

{

i=i+Len1;

Count=Count+1;

}

strcpy(Str3,(Str3+Len1));

}

 

printf(“\n\nNumber of occurences is:– %d”,Count);

getch();

}

 

 

8.13 Write a program that will copy m consecutive characters from a string s1 beginning at position n into another string s2.

 

Answer:

#include<stdio.h>

#include<conio.h>

 

#define MAX 50

 

void main()

{

char Str1[MAX],Str2[MAX];

int i,m,n,j;

 

clrscr();

 

printf(“Enter A String:–\n”);

scanf(“%[^\n]s”,Str1);

 

printf(“\nEnter Number of Characters Which U Wnat to Copy–>\n”);

scanf(“%d”,&m);

 

printf(“\nEnter Beginnig Index from Which U Want to Copy–>\n”);

scanf(“%d”,&n);

 

for(i=n-1,j=0;i<m+n;i++,j++)

{

Str2[j]=Str1[i];

}

 

Str2[m]=”;

 

printf(“\n\nCopied String is–> %s \n\n”,Str2);

getch();

}

 

 

8.14 Write a program to create a directory of students with roll numbers.The program should display the roll number for a specified name and vice-versa.

 

Answer:

#include<stdio.h>

#include<conio.h>

 

#define MAX 50

void main()

{

char Stu_Name[MAX][MAX],Name[MAX];

int Roll_No[MAX],n,i,Roll,Index;

 

clrscr();

 

printf(“How Many Student Name U Want to Enter\n\n”);

scanf(“%d”,&n);

 

printf(“Enter Roll No. & Students Name:–\n”);

 

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

{

scanf(“%d”,&Roll_No[i]);

scanf(“%s”,Stu_Name[i]);

}

 

printf(“\nEnter Student Roll No which U want to Search:–\n”);

scanf(“%d”,&Roll);

 

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

{

if(Roll==Roll_No[i])

{

Index=i;

}

}

 

printf(“\nName of Student is –> %s whose Roll No is:–%d”,Stu_Name[Index],Roll);

 

printf(“\n\nEnter Student Name which U want to Search:–\n”);

scanf(“%s”,Name);

 

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

{

if(strcmp(Stu_Name[i],Name)==0)

{

Index=i;

}

}

 

printf(“\n\nRoll No of is:– %d Student Whose Name is:– %s\n”,Roll_No[Index],Stu_Name[Index]);

getch();

}

 

 

 

8.15 Given a string char str[ ] =”123456789”; Write a program that displays the following:

            1

         2 3 2

      3 4 5 4 3

   4 5 6 7 6 5 4

5 6 7 8 9 8 7 6 5

 

 

answer:

#include<stdio.h>

#include<conio.h>

 

void main()

{

char Str[]=”123456789″;

int i,j,k,l;

clrscr();

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

{

for(k=4;k>i;k–)

{

printf(” “);

}

for(j=0,l=i;j<=i;j++,l++)

{

printf(“%c”,Str[l]);

}

l=l-2;

for(k=0;k<i;k++,l–)

printf(“%c”,Str[l]);

printf(“\n”);

}

getch();

 

}

 

 

 

 

E.BALAGURUSAMY SOLUTION PROGRAMMING IN ANSI C: CHAPTER-7


7.1 Write a program for fitting a straight line through a set of points (xi,

yi),i=1,2,3….n. The straight line equation is:

Y =mx+c

and the values of m and c are given by:

m=((n ∑(xi,yi))- (∑xi)(∑yi) )/( n(∑xi2)-(∑xi)2)

c=1/n(∑yi -m(∑xi))

All summations are from 1 to n.

Answer:

#include

#include

void main()

{

int i,n=10,v1,v2,x[10],y[10];

int total_x,total_y,total_xy,total_x2;

float m,c,temp,temp1;

clrscr();

printf(“Enter the values for x: “);

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

{

scanf(“%d”,&v1);

x[i]=v1;

}

printf(“Enter the values for y: “);

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

{

scanf(“%d”,&v2);

y[i]=v2;

}

total_x=total_y=total_xy=total_x2=0;

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

{

total_x=total_x+x[i];

total_y=total_y+y[i];

total_xy=total_xy+(x[i]*y[i]);

total_x2=total_x2+(x[i]*x[i]);

}

temp= total_x*total_y;

temp1=total_x*total_x;

m=((n*total_xy)-(temp))/((n*total_x2)-temp1);

c=((total_y)-(m*total_x))/n;

printf(” \nThe equation of the straight line is: “);

printf(” Y=%fX+%f”,m,c);

getch();

}

Output

Enter the values for x:

1 2 3 4 5 6 7 8 9 10

Enter the values for y:

1 2 3 4 5 6 7 8 9 10

The equation of the straight line is:

Y=1.00000X+0.000000

7.2 The daily maximum temperature recorded in 10 cities during the month of January (for all 31 days) have been tabulated as follows:

City

1 2 3 4 5 6 ……………………………10

Day

1

2

3

.

.

.

.

31

7.2. Write a program to read the table elements into a two-dimensional array temperature, and to find the city and day corresponding to

a) the highest temperature

b) the lowest temperature

Answer:

//Write a program to read the table elements into a two-dimensional array temperature, and to find the city and day corresponding to

//a) the highest temperature

//b) the lowest temperature

// Date : 16/03/2010

#include

#include

void main()

{

int Temp[2][2];

int i,j,City1,City2,MaxTemp,MinTemp;

clrscr();

printf(“Enter temperature:–\n\n”);

for(i=0;i<2;i++) { printf(“For City %d ->\n”,i);

for(j=0;j<2;j++) { printf(“For Day %d ->”,j);

scanf(“%d”,&Temp[i][j]);

}

}

clrscr();

printf(“Temperature Matix :— \n”);

printf(” City \n “);

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

printf(“%d “,i+1);

printf(“\n Day\n”);

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

{

printf(” %d “,i+1);

for(j=0;j<2;j++)

{

printf(” %d”,Temp[i][j]);

}

printf(“\n”);

}

MinTemp=MaxTemp=Temp[0][0];

City1=0;

City2=0;

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

{

for(j=0;j<2;j++)

{

if(MaxTemp<Temp[i][j]) { MaxTemp=Temp[i][j]; City1=j+1; } if(MinTemp>Temp[i][j])

{

MinTemp=Temp[i][j];

City2=j+1;

}

}

}

printf(“\n\nHighest Temperature of City %d is %d\n”,City1,MaxTemp);

printf(“Lowest Temperature of City %d is %d\n”,City2,MinTemp);

getch();

}

 

 

7.3 An election is contested by 5 candidates. The candidate are numbered are 1 to 5

and the voting is done by marking the candidate number on the ballot paper. Write

a program to read the ballots and count the votes cast for each candidate using an

array variable count. In case, a number, read is outside the range 1 to 5,the ballot

should be considered as a ‘spoilt ballot’ and the program should also count the

number of spoilt ballots.

 

Program:–

/* An election is contested by 5 candidates.

The candidate are numbered are 1 to 5 and the voting is done by marking the candidate number on the ballot paper. Write a program to read the ballots and count the votes cast for each candidate using an array variable count. In case, a number, read is outside the range 1 to 5,the ballot should be considered as a ‘spoilt ballot’ and the program should also count the number of spoilt ballots. */

// Date March 16,2010

#include

#include

void main()

{

int i,vote[5],c1=0,c2=0,c3=0,c4=0,c5=0,count=0,count_sp=0,v;

clrscr();

printf(“Enter your votes for 5 candidates:”);

for(i=1;i<=5;i++)

{

scanf(“%d”,&v);

vote[i]=v;

}

for(i=1;i<=5;i++)

{

if(vote[i]==1)

c1=c1+1;

else

{

if(vote[i]==2)

c2=c2+1;

else

{

if(vote[i]==3)

c3=c3+1;

else

{

if(vote[i]==4)

c4=c4+1;

else

if(vote[i]==5)

c5=c5+1;

}

}

}

}

printf(” votes to candidate1=%d”,c1);

printf(” \nvotes to candidate2=%d”,c2);

printf(“\n votes to candidate3=%d”,c3);

printf(” \nvotes to candidate4=%d”,c4);

printf(” \nvotes to candidate5=%d”,c5);

for(i=1;i<=5;i++)

{

if(vote[i]<=5)

count=count+1;

else

count_sp=count_sp+1;

}

printf(” The number of valid votes is:%d”,count);

printf(” \nThe number of spoilt votes is:%d”,count_sp);

getch();

}

Output

Enter your votes for 5 candidates:

1

3

1

8

2

Votes to Candidate 1: 2

Votes to Candidate 2: 1

Votes to Candidate 3:1

Votes to Candidate 4:0

Votes to Candidate 5:0

The number of valid votes is: 4

The number of spoilt votes is: 1

7.51 The annual examination results of 10 students are tabulated as follows:

Roll No. Subject1 Subject2 Subject3

.

.

.

.____________________________________________________________________

Write a program to read the data and determine the following:

(a) Total marks obtained by each student.

(b) The highest marks in each subject and the Roll No. of the student who secured it.

(c) The student who obtained the highest total marks.

 

Program:–

/* The annual examination results of 10 students are tabulated as follows:

Roll No. Subject1 Subject2 Subject3

.

.

.

.

Write a program to read the data and determine the following:

(a) Total marks obtained by each student.

(b) The highest marks in each subject and the Roll No. of the student who secured it.

(c) The student who obtained the highest total marks.

*/

// Date March 16,2010

#include

#include

#define MAX 10

void main()

{

int i,roll,m1,m2,m3,sub1[MAX],sub2[MAX],sub3[MAX];

int total_sub1,total_sub2,total_sub3,total[MAX];

int max,max1,max2,max3,roll1,roll2,roll3;

clrscr();

printf(“Enter the marks for subject1 of all the students: “);

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

scanf(“%d”,&sub1[i]);

printf(“Enter the marks for subject2 of all the students: “);

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

scanf(“%d”,&sub2[i]);

printf(“Enter the marks for subject3 of all the students: “);

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

scanf(“%d”,&sub3[i]);

total_sub1=total_sub2=total_sub3=0;

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

{

total_sub1=total_sub1+sub1[i];

total_sub2=total_sub2+sub2[i];

total_sub3=total_sub3+sub3[i];

total[i]=sub1[i]+sub2[i]+sub3[i];

}

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

{

printf(“The total marks obtained by the student%d is =%d\n”,i+1,total[i]);

}

max1=sub1[0];

max2=sub2[0];

max3=sub3[0];

max=total[0];

roll1=0;

roll2=0;

roll3=0;

roll=0;

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

{

if(max1<sub1[i])

{

max1=sub1[i];

roll1=i+1;

}

if(max2<sub2[i])

{

max2=sub2[i];

roll2=i+1;

}

if(max3<sub3[i])

{

max3=sub3[i];

roll3=i+1;

}

if(max<total[i])

{

max=total[i];

roll=i+1;

}

}

printf(“\nThe highest marks in subject1 is %d and the roll number is %d”,max1,roll1);

printf(“\nThe highest marks in subject2 is %d and the roll number is %d”,max2,roll2);

printf(“\nThe highest marks in subject3 is %d and the roll number is %d”,max3,roll3);

printf(“\n The highest total marks is %d and the roll number is %d “,max,roll);

getch();

}

 

 

7.6 Given are one dimensional arrays A and B which are sorted in ascending

order. Write a program to merge them into a single sorted array C that contains

every item form array A and B, in ascending order.

 

 

Program:–

// Given are one dimensional arrays A and B which are sorted in ascending

// order. Write a program to merge them into a single sorted array C that contains

// every item form array A and B, in ascending order.

//Date: 16/03/2010

#include

#include

#define MAX 50

void main()

{

int a[MAX],b[MAX],c[MAX];

int ax,bx,cx,n,m,mn;

clrscr();

ax=bx=cx=0;

printf(“Enter no. of elements of array : “);

scanf(“%d %d”,&n,&m);

printf(“Enter elements of first array :\n”);

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

scanf(“%d”,&a[i]);

printf(“Enter elements of Second array :”);

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

scanf(“%d”,&b[i]);

mn=m+n;

while(ax
{

if(a[ax]<b[bx])

{

c[cx]=a[ax];

ax++;

}

else

{

c[cx]=b[bx];

bx++;

}

cx++;

}

if(ax==n)

{

while(bx<m)

{

c[cx]=b[bx];

bx++;

cx++;

}

}

else

{

while(ax<n)

{

c[cx]=a[ax];

ax++;

cx++;

}

}

//sorted array

printf(“the sorted array is : \n”);

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

printf(“%d “,c[i]);

getch();

}

7.7 Write a program that will read the values of elements of A and B and produce the

product matrix C.

 

 

 

Program:–

// Write a program that will read the values of elements of A and B and produce the

// product matrix C.

//Date: 16/03/2010

#include

#include

#define MAX 10

void main()

{

int a[MAX][MAX],b[MAX][MAX],c[MAX][MAX];

int i,j,k,row,col;

clrscr();

printf(“Enter row of matrix”);

scanf(“%d”,&row);

printf(“Enter column of matrix”);

scanf(“%d”,&col);

printf(“Enter first matrix\n”);

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

for(j=0;j<col;j++)
scanf(“%d”,&a[i][j]);

printf(“\nEnter second matrix \n”);

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

for(j=0;j<col;j++)
scanf(“%d”,&b[i][j]);

printf(“\nFirst matrix is : \n”);

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

{

for(j=0;j<col;j++)
printf(“%d “,a[i][j]);

printf(“\n”);

}

printf(“\nSecond matrix is\n”);

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

{

for(j=0;j<col;j++)
printf(“%d “,b[i][j]);

printf(“\n”);

}

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

for(j=0;j<col;j++)
{ c[i][j]=0;

for(k=0;k<col;k++)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);

}

printf(“\nMultiplication is\n”);

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

{

for(j=0;j<col;j++)
printf(“%d “,c[i][j]);

printf(“\n”);

}

getch();

}

 

 

7.8 Write a program that fills a five-by-five as follows:

• Upper left triangle with +1s

• Lower right triangle with -1s

• Right to left diagonal with zeros

Display the contents of the matrix using not more than two printf statements.

 

 

 

Program:–

//Write a program that fills a five-by-five as follows:

//• Upper left triangle with +1s

//• Lower right triangle with -1s

//• Right to left diagonal with zeros

//Display the contents of the matrix using not more than two printf statements.

// Date : 16/03/2010

#include

#include

void main()

{

int A[5][5];

int a,i,k,j;

clrscr();

a=3;

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

{

for(j=0;j<=a;j++)

{

A[i][j]=+1;

}

a–;

}

j=4;

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

{

A[i][j]=0;

j–;

}

a=4;

for(i=1;i<=4;i++) { for(j=4;j>=a;j–)

{

A[i][j]=-1;

}

a–;

}

printf(“Array is:–\n\n”);

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

{

for(j=0;j<=4;j++) printf(“%d “,A[i][j]); printf(“\n”); } getch(); } 7.9 Write a program to implement selection sort. Algorithm:– Step 1: Read Array A. Step 2: For k=0 to 9 repeat Step 3 to Step 8. Step 3: Compute Small=A[k] & Loc=k. Step 4: For i=0 to 9 repeat Step 5 to Step 7 otherwise go to Step 7. Step 5: Check Small>A[i] then go to Step 6 otherwise go to Step 4.

Step 6: Compute Small=A[i] & Loc=i.

Step 7: Compute A[Loc]=A[k], A[k]=Small.

Step 8: Display Sorted Array A.

Flowchart:–

Program:–

//Write a program to implement selection sort.

// Date : 16/03/2010

#include

#include

void main()

{

int A[10];

int i,k,Small,Loc;

clrscr();

printf(“Enter Elements of Array:—\n”);

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

scanf(“%d”,&A[i]);

for(k=0;k<=9;k++)

{

Small=A[k];

Loc=k;

for(i=k;i<=9;i++) if(Small>A[i])

{

Small=A[i];

Loc=i;

}

A[Loc]=A[k];

A[k]=Small;

}

printf(“Sorted Array is:–\n\n”);

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

printf(“%d “,A[i]);

getch();

}

7.10 Write a program to implement Binary Search algorithm.

 

 

 

Program:–

//Write a program to implement Binary Search algorithm.

// Date : 16/03/2010

#include

#include

void main()

{

int Str[10];

int i,Beg,End,Mid,Item;

clrscr();

Beg=0;

End=9;

Mid=(Beg+End)/2;

printf(“Enetr Any Sorted Array:–\n”);

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

scanf(“%d”,&Str[i]);

printf(“Enter Item Which U want to Search:–\n”);

scanf(“%d”,&Item);

while((Item!=Str[Mid])&&(Beg<=End))

{

if(Item<Str[Mid]) End=Mid-1; else Beg=Mid+1; Mid=(Beg+End)/2; } if(Beg>End)

printf(“Item Not Found\n”);

else

printf(“%d Found At Index %d\n”,Item,Mid);

getch();

}

 

7.11 Write a program that will compute the length of a given character string.

 

 

Program:–

//Write a program that will compute the length of a given character string.

// Date : 16/03/2010

#include

#include

void main()

{

char Str[50];

int i,Len;

clrscr();

Len=0;

printf(“Enter a String:—\n”);

scanf(“%[^\n]s”,&Str);

for(i=0;Str[i]!=”;i++)

Len=Len+1;

printf(“Length of String is %d”,Len);

getch();

}

7.12 Write a program that will count the number occurrences of a specified character in a

given line of text.

 

 

 

Program:–

//Write a program that will count the number occurrences of a specified character in a

// given line of text.

// Date : 16/03/2010

#include

#include

void main()

{

char Str[50],CheckChar;

int i,Count,Len;

clrscr();

Count=0;

printf(“Enter a String:—\n”);

scanf(“%[^\n]s”,&Str);

Len=strlen(Str);

fflush(stdin);

printf(“Enter a charatcer:–\n”);

scanf(“%c”,&CheckChar);

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

if(CheckChar==Str[i])

Count=Count+1;

printf(“Number of occurences of %c is %d”,CheckChar,Count);

getch();

}

 

 

7.13 Write a program to read a matrix of size m*n and print its transpose.

 

 

Program:–

//Write a program to read a matrix of size m*n and print its transpose.

// Date : 16/03/2010

#include

#include

#define MAX 10

void main()

{

int A[MAX][MAX],C[MAX][MAX];

int Row,Col,i,j;

clrscr();

printf(“Enter Number of Rows:–\n”);

scanf(“%d”,&Row);

printf(“Enter Number of Column:–\n”);

scanf(“%d”,&Col);

printf(“Enter Matrix:—\n”);

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

for(j=0;j<Col;j++)
scanf(“%d”,&A[i][j]);

clrscr();

printf(“Matrix:—\n”);

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

{

for(j=0;j<Col;j++)
printf(“%d “,A[i][j]);

printf(“\n”);

}

for(i=0;i<Col;i++)
for(j=0;j<Row;j++)

C[i][j]=A[j][i];

printf(“Transpose of Matrix:—\n”);

for(i=0;i<Col;i++)
{

for(j=0;j<Row;j++)

printf(“%d “,C[i][j]);

printf(“\n”);

}

getch();

}

7.3 An election is contested by 5 candidates. The candidate are numbered are 1 to 5

      and the voting is done by marking the candidate number on the ballot paper. Write

      a program to read the ballots and count the votes cast for each candidate using an

      array variable count. In case, a number, read is outside the range 1 to 5,the ballot

      should be considered as a ‘spoilt ballot’ and the program should also count the

      number of spoilt ballots.

 

 

 

 

 

 

 

Algorithm:–

 

Step1.  Initialize c1,c2, c3,c4,c5,count,count_sp with 0.

Step2. For i=0 to i=5, repeat step3.

Step3. Enter the value of v and store in vote[i]

Step4. For i=0 to i=5, repeat from step5 till step14 and for i>5,go to step15.

Step5. Check if vote[i]==1,if true, go to step6,if false go to step7.

Step6.Calculate c1=c1+1

Step7. Check if vote[i]==2,if true, go to step8,if false go to step9.

Step8.Calculate c2=c2+2

Step9.Check if vote[i]==3,if true, go to step10,if false go to step11.

Step10. Calculate c3=c3+2

Step 11.Check if vote[i]==4,if true, go to step12,if false go to step13.

Step12.Calculate c4=c4+2

Step13.Check if vote[i]==5,if true, go to step14,if false go to step15.

Step14.Calculate c5=c5+2

Step15. Display c1,c2,c3,c4 and c5.

Step16. For i=0 to i=5, repeat from step 17 to step, and i>5,go to step 20

Step17.Check if vote[i]<5,if true go to step18 and if false, go to step 19.

Step18.count=count+1 and go to step 20.

Step19.count_sp=count_sp+1 and go to step 20.

Step20. Display count and count_sp

Step21. Stop.

Flowchart:–

 

Program:–

 

/* An election is contested by 5 candidates.

The candidate are numbered are 1 to 5 and the voting is done by marking the candidate number on the ballot paper. Write a program to read the ballots and count the votes cast for each candidate using an array variable count.  In case, a number, read is outside the range 1 to 5,the ballot should be considered as a ‘spoilt ballot’ and the program should also count the number of spoilt ballots. */

// Date March 16,2010

#include<stdio.h>

#include<conio.h>

void main()

{

int i,vote[5],c1=0,c2=0,c3=0,c4=0,c5=0,count=0,count_sp=0,v;

clrscr();

printf(“Enter your votes for 5 candidates:”);

for(i=1;i<=5;i++)

{

scanf(“%d”,&v);

vote[i]=v;

}

for(i=1;i<=5;i++)

{

if(vote[i]==1)

c1=c1+1;

else

{

if(vote[i]==2)

c2=c2+1;

else

{

if(vote[i]==3)

c3=c3+1;

else

{

if(vote[i]==4)

c4=c4+1;

else

if(vote[i]==5)

c5=c5+1;

}

}

}

}

printf(” votes to candidate1=%d”,c1);

printf(” \nvotes to candidate2=%d”,c2);

printf(“\n votes to candidate3=%d”,c3);

printf(” \nvotes to candidate4=%d”,c4);

printf(” \nvotes to candidate5=%d”,c5);

for(i=1;i<=5;i++)

{

if(vote[i]<=5)

count=count+1;

else

count_sp=count_sp+1;

}

printf(” The number of valid votes  is:%d”,count);

printf(” \nThe number of spoilt votes is:%d”,count_sp);

getch();

}

Output

Enter your votes for 5 candidates:

1

3

1

8

2

Votes to Candidate 1: 2

Votes to Candidate 2: 1

Votes to Candidate 3:1

Votes to Candidate 4:0

Votes to Candidate 5:0

The number of valid votes is:  4

The number of spoilt votes is: 1

 

5.1 The annual examination results of 10 students are tabulated as follows:

 

Roll No.              Subject1          Subject2                          Subject3

.

.

.

.____________________________________________________________________

 

Write a program to read the data and determine the following:

(a)   Total marks obtained by each student.

(b)    The highest marks in each subject and the Roll No. of the student who secured it.

(c)     The student who obtained the highest total marks.

Algorithm:–

 

Step1.  Declare

Step2.  For i=0 to i<10, Enter sub1[i]

Step3. For i=0 to i<10, Enter sub2[i]

Step4. For i=0 to i<10, Enter sub3[i]

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Program:–

 

/* The annual examination results of 10 students are tabulated as follows:

Roll No.              Subject1                Subject2                           Subject3

.

.

.

.

Write a program to read the data and determine the following:

(a)            Total marks obtained by each student.

(b)            The highest marks in each subject and the Roll No. of the student who secured it.

(c)            The student who obtained the highest total marks.

*/

// Date March 16,2010

#include<stdio.h>

#include<conio.h>

#define MAX 10

void main()

{

int i,roll,m1,m2,m3,sub1[MAX],sub2[MAX],sub3[MAX];

int total_sub1,total_sub2,total_sub3,total[MAX];

int max,max1,max2,max3,roll1,roll2,roll3;

clrscr();

printf(“Enter the marks for subject1 of all the students: “);

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

scanf(“%d”,&sub1[i]);

printf(“Enter the marks for subject2 of all the students: “);

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

scanf(“%d”,&sub2[i]);

printf(“Enter the marks for subject3 of all the students: “);

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

scanf(“%d”,&sub3[i]);

total_sub1=total_sub2=total_sub3=0;

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

{

total_sub1=total_sub1+sub1[i];

total_sub2=total_sub2+sub2[i];

total_sub3=total_sub3+sub3[i];

total[i]=sub1[i]+sub2[i]+sub3[i];

}

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

{

printf(“The total marks obtained by the student%d is =%d\n”,i+1,total[i]);

}

max1=sub1[0];

max2=sub2[0];

max3=sub3[0];

max=total[0];

roll1=0;

roll2=0;

roll3=0;

roll=0;

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

{

if(max1<sub1[i])

{

max1=sub1[i];

roll1=i+1;

}

if(max2<sub2[i])

{

max2=sub2[i];

roll2=i+1;

}

if(max3<sub3[i])

{

max3=sub3[i];

roll3=i+1;

}

if(max<total[i])

{

max=total[i];

roll=i+1;

}

}

printf(“\nThe highest marks in subject1 is %d and the roll number is %d”,max1,roll1);

printf(“\nThe highest marks in subject2 is %d and the roll number is %d”,max2,roll2);

printf(“\nThe highest marks in subject3 is %d and the roll number is %d”,max3,roll3);

printf(“\n The highest total marks is %d and the roll number is %d “,max,roll);

getch();

}

 

7.6 Given are one dimensional arrays A and B which are sorted in ascending

      order. Write a program to merge them into a single sorted array C that contains

      every item form array A and B, in ascending order.

 

 

 

 

 

Algorithm:–

 

Step 1: Read m, n, Array a & Array b.

Step 2: Store 0 to ax, bx and cx.

Step 3: Compute mn=m+n

Step 4: Repeat Step 5 to Step 8 while ax<n && bx<m otherwise go to Step 9

Step 5: Check a[ax]<b[bx] then go to Step 6 otherwise go to Step 7

Step 6: Compute c[cx]=a[ax], ax=ax+1

Step 7: Compute c[cx]=b[bx], bx=bx+1

Step 8: Compute cx=cx+1

Step 9: Check ax==n then go to Step 10 otherwise go to Step 12

Step 10: Repeat Step 11 while bx<m

Step 11: Compute c[cx]=b[bx], bx=bx+1, cx=cx+1.

Step 12: Repeat Step 13 while ax<n

Step 13: Compute c[cx]=a[ax], ax=ax+1, cx=cx+1.

Step 14: Display Sorted Array c.

Flowchart:–

 

 

 

Program:–

 

// Given are one dimensional arrays A and B which are sorted in ascending

//      order. Write a program to merge them into a single sorted array C that contains

//      every item form array A and B, in ascending order.

//Date: 16/03/2010

#include<stdio.h>

#include<conio.h>

#define MAX 50

void main()

{

int a[MAX],b[MAX],c[MAX];

int ax,bx,cx,n,m,mn;

clrscr();

ax=bx=cx=0;

printf(“Enter no. of elements of array : “);

scanf(“%d %d”,&n,&m);

printf(“Enter elements of first array :\n”);

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

scanf(“%d”,&a[i]);

printf(“Enter elements of Second array :”);

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

scanf(“%d”,&b[i]);

mn=m+n;

while(ax<n && bx<m)

{

if(a[ax]<b[bx])

{

c[cx]=a[ax];

ax++;

}

else

{

c[cx]=b[bx];

bx++;

}

cx++;

}

if(ax==n)

{

while(bx<m)

{

c[cx]=b[bx];

bx++;

cx++;

}

}

else

{

while(ax<n)

{

c[cx]=a[ax];

ax++;

cx++;

}

}

//sorted array

printf(“the sorted array is : \n”);

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

printf(“%d “,c[i]);

getch();

}

7.7 Write a program that will read the values of elements of A and B and produce the

       product matrix C.

 

 

 

Algorithm:–

 

Step 1: Read row, col, Array a and Array b.

Step 2: Display Array a and b.

Step 3: For i=0 to row repeat Step 4 to Step 7

Step 4: For j=0 to col repeat Step 5 to Step 7

Step 5: Store 0 to c[i][j]

Step 6: For k=0 to col repeat Step 7

Step 7: Compute c[i][j]=c[i][j]+(a[i][k]*b[k][j])

Step 8: Display c.

 

 

 

 

 

 

 

 

Flowchart:–

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Program:–

 

// Write a program that will read the values of elements of A and B and produce the

// product matrix C.

//Date: 16/03/2010

#include<stdio.h>

#include<conio.h>

#define MAX 10

void main()

{

int a[MAX][MAX],b[MAX][MAX],c[MAX][MAX];

int i,j,k,row,col;

clrscr();

printf(“Enter row of matrix”);

scanf(“%d”,&row);

printf(“Enter column of matrix”);

scanf(“%d”,&col);

printf(“Enter first matrix\n”);

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

for(j=0;j<col;j++)

scanf(“%d”,&a[i][j]);

printf(“\nEnter second matrix \n”);

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

for(j=0;j<col;j++)

scanf(“%d”,&b[i][j]);

printf(“\nFirst matrix is : \n”);

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

{

for(j=0;j<col;j++)

printf(“%d “,a[i][j]);

printf(“\n”);

}

printf(“\nSecond matrix is\n”);

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

{

for(j=0;j<col;j++)

printf(“%d “,b[i][j]);

printf(“\n”);

}

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

for(j=0;j<col;j++)

{   c[i][j]=0;

for(k=0;k<col;k++)

c[i][j]=c[i][j]+(a[i][k]*b[k][j]);

}

printf(“\nMultiplication is\n”);

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

{

for(j=0;j<col;j++)

printf(“%d “,c[i][j]);

printf(“\n”);

}

getch();

}

 

 

 

 

 

7.8 Write a program that fills a five-by-five as follows:

  • Upper left triangle with +1s
  • Lower right triangle with -1s
  • Right to left diagonal with zeros

       Display the contents of the matrix using not more than two printf statements.

 

 

 

 

 

Algorithm:–

 

Step 1: Store Upper left triangle with +1s

Step 2: Store Lower right triangle with -1s

Step 3: Store Right to left diagonal with zeros

Step 4: Display A

 

 

 

 

 

 

 

 

 

 

Flowchart:–

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Program:–

 

//Write a program that fills a five-by-five as follows:

//•         Upper left triangle with +1s

//•         Lower right triangle with -1s

//•         Right to left diagonal with zeros

//Display the contents of the matrix using not more than two printf statements.

// Date : 16/03/2010

#include<stdio.h>

#include<conio.h>

void main()

{

int A[5][5];

int a,i,k,j;

clrscr();

a=3;

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

{

for(j=0;j<=a;j++)

{

A[i][j]=+1;

}

a–;

}

j=4;

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

{

A[i][j]=0;

j–;

}

a=4;

for(i=1;i<=4;i++)

{

for(j=4;j>=a;j–)

{

A[i][j]=-1;

}

a–;

}

printf(“Array is:–\n\n”);

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

{

for(j=0;j<=4;j++)

printf(“%d  “,A[i][j]);

printf(“\n”);

}

getch();

}

7.9 Write a program to implement selection sort.

 

 

 

Algorithm:–

 

Step 1: Read Array A.

Step 2: For k=0 to 9 repeat Step 3 to Step 8.

Step 3: Compute Small=A[k] & Loc=k.

Step 4: For i=0 to 9 repeat Step 5 to Step 7 otherwise go to Step 7.

Step 5: Check Small>A[i] then go to Step 6 otherwise go to Step 4.

Step 6: Compute Small=A[i] & Loc=i.

Step 7: Compute A[Loc]=A[k], A[k]=Small.

Step 8: Display Sorted Array A.

 

Flowchart:–

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Program:–

 

//Write a program to implement selection sort.

// Date : 16/03/2010

#include<stdio.h>

#include<conio.h>

void main()

{

int A[10];

int i,k,Small,Loc;

clrscr();

printf(“Enter Elements of Array:—\n”);

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

scanf(“%d”,&A[i]);

for(k=0;k<=9;k++)

{

Small=A[k];

Loc=k;

for(i=k;i<=9;i++)

if(Small>A[i])

{

Small=A[i];

Loc=i;

}

A[Loc]=A[k];

A[k]=Small;

}

printf(“Sorted Array is:–\n\n”);

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

printf(“%d  “,A[i]);

getch();

}

7.10 Write a program to implement Binary Search algorithm.

 

Algorithm:–

 

Step 1: Store 0 to Beg & 9 to End.

Step 2: Compute Mid=(Beg+End)/2.

Step 3: Read a Sorted Array Str & an Item to Search.

Step 4: Repeat Step 5 to Step 8 while Item!=Str[Mid])&&(Beg<=End) otherwise go to Step 9

Step 5: Check Item<Str[Mid] then go to Step 6 otherwise go to Step 7

Step 6: Compute End=Mid-1

Step 7: Compute Beg=Mid+1

Step 8: Compute Mid=(Beg+End)/2

Step 9: Check Beg>End go to Step 10 otherwise go to Step 11

Step 10: Display “Item Not Found”

Step 11: Display “Item Found”

 

Flowchart:–

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Program:–

 

//Write a program to implement Binary Search algorithm.

// Date : 16/03/2010

#include<stdio.h>

#include<conio.h>

void main()

{

int Str[10];

int i,Beg,End,Mid,Item;

clrscr();

Beg=0;

End=9;

Mid=(Beg+End)/2;

printf(“Enetr Any Sorted Array:–\n”);

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

scanf(“%d”,&Str[i]);

printf(“Enter Item Which U want to Search:–\n”);

scanf(“%d”,&Item);

while((Item!=Str[Mid])&&(Beg<=End))

{

if(Item<Str[Mid])

End=Mid-1;

else

Beg=Mid+1;

Mid=(Beg+End)/2;

}

if(Beg>End)

printf(“Item Not Found\n”);

else

printf(“%d Found At Index %d\n”,Item,Mid);

getch();

}

7.11 Write a program that will compute the length of a given character string.

 

Algorithm:–

 

Step 1: Read a string Str.

Step 2: For i=0 to End of String repeat Step 3 to Step

Step 3: Compute Len=Len+1

Step 4: Display Len.

Flowchart:–

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Program:–

 

//Write a program that will compute the length of a given character string.

// Date : 16/03/2010

#include<stdio.h>

#include<conio.h>

void main()

{

char Str[50];

int i,Len;

clrscr();

Len=0;

printf(“Enter a String:—\n”);

scanf(“%[^\n]s”,&Str);

for(i=0;Str[i]!=”;i++)

Len=Len+1;

printf(“Length of String is %d”,Len);

getch();

}

7.12 Write a program that will count the number occurrences of a specified character in a

         given line of text.

 

 

 

 

 

Algorithm:–

 

Step 1: Read a string Str & a Character CheckChar

Step 2: Length of String is Len

Step 3: For i=0 to Len repeat Step 4 to Step 5

Step 4: Check CheckChar==Str[i] go to Step 5 otherwise go to Step 3

Step 5: Count=Count+1

Step 6: Display Count

 

 

 

 

 

 

 

Flowchart:–

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Program:–

 

//Write a program that will count the number occurrences of a specified character in a

//         given line of text.

// Date : 16/03/2010

#include<stdio.h>

#include<conio.h>

void main()

{

char Str[50],CheckChar;

int i,Count,Len;

clrscr();

Count=0;

printf(“Enter a String:—\n”);

scanf(“%[^\n]s”,&Str);

Len=strlen(Str);

fflush(stdin);

printf(“Enter a charatcer:–\n”);

scanf(“%c”,&CheckChar);

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

if(CheckChar==Str[i])

Count=Count+1;

printf(“Number of occurences of %c is %d”,CheckChar,Count);

getch();

}

 

 

 

 

 

7.13 Write a program to read a matrix of size m*n and print its transpose.

 

 

 

 

Algorithm:–

 

Step 1: Read Row, Col & Matrix A

Step 2: Display A

Step 3: For i=0 to Col repeat Step 4 to Step 5 otherwise go to Step 6

Step 4: For j=0 to Row repeat Step 5 otherwise go to Step 3

Step 5: Compute C[i][j]=A[j][i]

Step 6: Display C

 

 

 

 

 

 

 

 

 

 

 

 

 

Flowchart:–

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Program:–

 

//Write a program to read a matrix of size m*n and print its transpose.

// Date : 16/03/2010

#include<stdio.h>

#include<conio.h>

#define MAX 10

void main()

{

int A[MAX][MAX],C[MAX][MAX];

int Row,Col,i,j;

clrscr();

printf(“Enter Number of Rows:–\n”);

scanf(“%d”,&Row);

printf(“Enter Number of Column:–\n”);

scanf(“%d”,&Col);

printf(“Enter Matrix:—\n”);

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

for(j=0;j<Col;j++)

scanf(“%d”,&A[i][j]);

clrscr();

printf(“Matrix:—\n”);

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

{

for(j=0;j<Col;j++)

printf(“%d  “,A[i][j]);

printf(“\n”);

}

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

for(j=0;j<Row;j++)

C[i][j]=A[j][i];

printf(“Transpose of Matrix:—\n”);

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

{

for(j=0;j<Row;j++)

printf(“%d  “,C[i][j]);

printf(“\n”);

}

getch();

}

7.14 Every book published by international publishers should carry an International

        Standard Book Number (ISBN). It is a 10 character 4 part number as shown below.

 

                                                0-07-041183-2

The first part denotes the region, the second represents publisher, the third identifies the book and the fourth is the check digit. The check digit is computed as follows:

 

Sum= (1*first digit) + (2*second digit) + (3*third digit)+…………….+ (9*ninth digit)

 

Check digit is the remainder when Sum is divided by 11. Write a program that reads a given ISBN number and check whether it represents a valid ISBN.

 

Algorithm:–

Step 1: Read Array ISBN.

Step 2: Compute Sum=Sum+(i*ISBN[i]) for i=0 to 9

Step 3: Compute CheckDig=Sum%11

Step 4: Check CheckDig=ISBN[10] then go to Step 5 Otherwise go to Step 6

Step 5: Display “Valid ISBN”

Step 6: Display “Invalid ISBN”

 

Flowchart:–

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Program:–

 

//Write a program that reads a given ISBN number and check whether it represents a valid ISBN.

// Date : 16/03/2010

#include<stdio.h>

#include<conio.h>

#define MAX 10

void main()

{

int ISBN[11];

int i,j,Sum,CheckDig;

clrscr();

Sum=0;

printf(“Enter ISBN Number:—\n”);

for(i=1;i<=10;i++)

scanf(“%d”,&ISBN[i]);

for(i=1;i<=9;i++)

Sum=Sum+(i*ISBN[i]);

CheckDig=Sum%11;

if(CheckDig==ISBN[10])

printf(“\nValid ISBN\n”);

else

printf(“\nInvalid ISBN\n”);

getch();

}

 

 

 

7.15 Write a program to read two matrices A and B and print the following:

 

a)       A + B and

b)      A – B.

 

Algorithm:–

 

Step 1: Read   Row, Col, Array A & B.

Step 2: Display Array A & B.

Step 3: Compute Addition of Array A & B & Store in Array C.

Step 4: Display Array C

 

Flowchart:–

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Program:–

//Write a program to read two matrices A and B and print the following:

//a)       A + B and

//b)       A – B.

// Date : 16/03/2010

#include<stdio.h>

#include<conio.h>

#define MAX 10

void main()

{

int A[MAX][MAX],B[MAX][MAX],C[MAX][MAX];

int Row,Col,i,j;

clrscr();

printf(“Enter Number of Rows:–\n”);

scanf(“%d”,&Row);

printf(“Enter Number of Column:–\n”);

scanf(“%d”,&Col);

printf(“Enter First Matrix:—\n”);

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

for(j=0;j<Col;j++)

scanf(“%d”,&A[i][j]);

printf(“Enter Second Matrix:—\n”);

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

for(j=0;j<Col;j++)

scanf(“%d”,&B[i][j]);

clrscr();

printf(“First Matrix:—\n”);

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

{

for(j=0;j<Col;j++)

printf(“%d  “,A[i][j]);

printf(“\n”);

}

printf(“Second Matrix:—\n”);

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

{

for(j=0;j<Col;j++)

printf(“%d  “,B[i][j]);

printf(“\n”);

}

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

for(j=0;j<Col;j++)

C[i][j]=A[i][j]+B[i][j];

printf(“Addition of Matrix:—\n”);

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

{

for(j=0;j<Col;j++)

printf(“%d  “,C[i][j]);

printf(“\n”);

}

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

for(j=0;j<Col;j++)

C[i][j]=A[i][j]-B[i][j];

printf(“Subtration of Matrix:—\n”);

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

{

for(j=0;j<Col;j++)

printf(“%d  “,C[i][j]);

printf(“\n”);

}

getch();

}

Algorithm:–

Step 1: Read Array ISBN.

Step 2: Compute Sum=Sum+(i*ISBN[i]) for i=0 to 9

Step 3: Compute CheckDig=Sum%11

Step 4: Check CheckDig=ISBN[10] then go to Step 5 Otherwise go to Step 6

Step 5: Display “Valid ISBN”

Step 6: Display “Invalid ISBN”

Flowchart:–

Program:–

//Write a program that reads a given ISBN number and check whether it represents a valid ISBN.

// Date : 16/03/2010

#include

#include

#define MAX 10

void main()

{

int ISBN[11];

int i,j,Sum,CheckDig;

clrscr();

Sum=0;

printf(“Enter ISBN Number:—\n”);

for(i=1;i<=10;i++)

scanf(“%d”,&ISBN[i]);

for(i=1;i<=9;i++)

Sum=Sum+(i*ISBN[i]);

CheckDig=Sum%11;

if(CheckDig==ISBN[10])

printf(“\nValid ISBN\n”);

else

printf(“\nInvalid ISBN\n”);

getch();

}

7.15 Write a program to read two matrices A and B and print the following:

a) A + B and

b) A – B.

Program:–

//Write a program to read two matrices A and B and print the following:

//a) A + B and

//b) A – B.

// Date : 16/03/2010

#include

#include

#define MAX 10

void main()

{

int A[MAX][MAX],B[MAX][MAX],C[MAX][MAX];

int Row,Col,i,j;

clrscr();

printf(“Enter Number of Rows:–\n”);

scanf(“%d”,&Row);

printf(“Enter Number of Column:–\n”);

scanf(“%d”,&Col);

printf(“Enter First Matrix:—\n”);

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

for(j=0;j<Col;j++)
scanf(“%d”,&A[i][j]);

printf(“Enter Second Matrix:—\n”);

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

for(j=0;j<Col;j++)
scanf(“%d”,&B[i][j]);

clrscr();

printf(“First Matrix:—\n”);

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

{

for(j=0;j<Col;j++)
printf(“%d “,A[i][j]);

printf(“\n”);

}

printf(“Second Matrix:—\n”);

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

{

for(j=0;j<Col;j++)
printf(“%d “,B[i][j]);

printf(“\n”);

}

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

for(j=0;j<Col;j++)
C[i][j]=A[i][j]+B[i][j];

printf(“Addition of Matrix:—\n”);

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

{

for(j=0;j<Col;j++)
printf(“%d “,C[i][j]);

printf(“\n”);

}

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

for(j=0;j<Col;j++)
C[i][j]=A[i][j]-B[i][j];

printf(“Subtration of Matrix:—\n”);

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

{

for(j=0;j<Col;j++)
printf(“%d “,C[i][j]);

printf(“\n”);

}

getch();

}

Programming C 02 (Programming in C in 7 days! By: Siamak Sarmady)


Compiling and Running under Windows with Dev-CPP


To develop, compile and run the program in Bloodshed environment follow below steps. If you have
problem working with your compiler you may ask your problem in our support forums.
1- Run bloodshed and select “New -> Project” from File menu. In the appeared window enter a name
for your project (Figure 1.1). Also select “Console Application”, “C Project” and “Make default
Language” as the settings of your application.