Monthly Archives: June 2015


Simplify Boolean function using Karnaugh map method F (A, B, C, D): Σ (0, 2, 4, 5, 6, 7, 8, 10, 13, 15) Also, draw the corresponding logic circuit diagram. 8m Jun2007

Construct the Karnaugh map for the following function, and find the function in sum of product form. Draw the resultant logic diagram. F (A, B, C, D): Σ (0, 2, 4, 5, 6, 7, 8, 10, 13, 15). 5m Dec2007

 K-Map for F is:

Kmap006

Thus, the simplified equations for F (A, B, C, D) = Σ (0, 2, 4, 5, 6, 7, 8, 10, 13, 15)

are:

F = B|CD+|B|D+|AB

Logic diagram:-

Logic_Diag04

 

 

(b) Draw the logic diagram for a 4 x 4 random access memory. Assume that the cells of RAM are made of R – S flip-flop.                        5

 

D flip-flop using R – S flip-flop Solved Answer can be found on this link http://thalia.spec.gmu.edu/~pparis/classes/notes_101/node116.html

Write a program in ‘C’ language that accepts the name of a file as input and prints those lines of the file which have the word ‘this’. 10m Dec2007

Write a program in ‘C’ language that accepts the name of a file as input and prints those lines of the file which have the word ‘this’. 10m Dec2007 

 

#include<stdio.h>
void main()
{
FILE *fp;
int cnt=0;
char str[80],lines[400];
clrscr();
if ((fp=fopen(“test.txt”,”r”))== NULL)
{
printf(“File does not exist\n”);
exit(0);
}
while(!(feof(fp)))
{
fgets(str,80,fp);
if(strcmp(“this”,str))
{
fgets(lines,400,fp);
printf(“%s”,lines);
}
}
fclose(fp);
getch();
}

Code:

#include<stdio.h>
void main()
{
FILE *fp;
int cnt=0;
char str[80],lines[400];
clrscr();
if ((fp=fopen("test.txt","r"))== NULL)
{
printf("File does not exist\n");
exit(0);
}
while(!(feof(fp)))
{
fgets(str,80,fp);
if(strcmp("this",str))
{
fgets(lines,400,fp);
printf("%s",lines);
}
}
fclose(fp);
getch();
}

Screen Shots:

C_program_File_Print_Line

C_program_File_Print_Line_Output

 

Write a program in ‘C’ language to convert a decimal number into binary number. 10m Dec2007

 

Similar program can be found on this link http://cssimplified.com/assignments/a-c-program-that-takes-a-decimal-number-and-converts-it-into-binary-octal-and-hexadecimal-equivalents-your-program-should-have-functions-for-each-type-of-conversion-these-functions-should-implement

 

Write a program in ‘C’ language to add two matrices. 10m Dec2007

 

Solved program can be found on this link http://cssimplified.com/c-programming/an-interactive-c-program-to-add-two-matrices-or-subtract-two-matrices

 

A program in ‘C’ language to display the names and seat numbers of all passengers of a bus in the form of a singly linked list. Use pointers. 10m Dec2007

Write a program in ‘C’ language to display the names and seat numbers of all passengers of a bus in the form of a singly linked list. Use pointers. 10m Dec2007

 

#include<stdio.h>
struct node
{
int seat;
char name[20];
struct node *next;
};
typedef struct node node; //with this Use “node” instead of “struct node”
node *root=NULL; //Global variable “root” pointer
node *create_node(int,char*); //Declaration
void insert(int,char*); //Declaration
void display_list(node *); //Declaration

void main()
{
clrscr();
display_list(root);
insert(1,”SAMEER”);
insert(2,”MAHESH”);
insert(3,”VARUN”);
insert(4,”RAHUL”);
display_list(root);
getch();
}

node *create_node(int x,char *nm)
{
node *temp;
temp=(node*)malloc(sizeof(node));
temp->seat=x;
strcpy(temp->name,nm);
temp->next=NULL;
return temp;
}

void insert(int x,char *nm)
{
node *temp,*start;
start=root;
if(root==NULL)
{ root=create_node(x,nm);root->next=root;}
else
{
while(start->next!=root)
{
start=start->next;
} start->next=create_node(x,nm);
start->next->next=root;
}
}
void display_list(node *start)
{
if(start==NULL)
{ printf(“List is Empty!\n\n”); }
else
{
printf(“SEAT No.\tName of Passenger\n\n”);
while(start->next!=root)
{ printf(“%d\t\t”,start->seat);
printf(“%s\n”,start->name);
start=start->next;
}
printf(“%d\t\t”,start->seat);
printf(“%s\n”,start->name);
}
}

 

Code:

#include<stdio.h>
struct node
{
int seat;
char name[20];
struct node *next;
};
typedef struct node node; //with this Use "node" instead of "struct node"
node *root=NULL; //Global variable "root" pointer
node *create_node(int,char*); //Declaration
void insert(int,char*); //Declaration
void display_list(node *); //Declaration
void main()
{
clrscr();
display_list(root);
insert(1,"SAMEER");
insert(2,"MAHESH");
insert(3,"VARUN");
insert(4,"RAHUL");
display_list(root);
getch();
}
node *create_node(int x,char *nm)
{
node *temp;
temp=(node*)malloc(sizeof(node));
temp->seat=x;
strcpy(temp->name,nm);
temp->next=NULL;
return temp;
}
void insert(int x,char *nm)
{
node *temp,*start;
start=root;
if(root==NULL)
{ root=create_node(x,nm);root->next=root;}
else
{
while(start->next!=root)
{
start=start->next;
} start->next=create_node(x,nm);
start->next->next=root;
}
}
void display_list(node *start)
{
if(start==NULL)
{ printf("List is Empty!\n\n"); }
else
{
printf("SEAT No.\tName of Passenger\n\n");
while(start->next!=root)
{ printf("%d\t\t",start->seat);
printf("%s\n",start->name);
start=start->next;
}
printf("%d\t\t",start->seat);
printf("%s\n",start->name);
}
 
}

Screen Shots:

C_program_Singly_link_Name

C_program_Singly_link_Name_Output

 

 

Explain any five functions of <stdlib.h> library. 10m Dec2007

Solved program can be found on this link http://www.techonthenet.com/c_language/standard_library_functions/stdlib_h/

 

Write a program in ‘C’ that accepts a sentence ‘s’ and a word ‘w’ as input. Now, the program should print the starting position of right-most occurrence of ‘w’ in’s’. 10m Dec2007

 

Similar program can be found on this link http://cssimplified.com/c-programming/write-the-functions-to-perform-the-following-10m-dec2005-2

A program in ‘C’ language which accepts enrollment number as input and prints the name of student. pairs of students in the form of a matrix. 10m Dec2007

Write a program in ‘C’ language which accepts the enrollment number of a student as input and prints the name of that student. The program should initially store information about the (name, enrollment number) pairs of students in the form of a matrix. 10m Dec2007

 

#include<stdio.h>
struct student
{
unsigned long int ENROL;
char NAME[15];
}STUD[12]={
{102038400,”GANESH”},
{102038401,”MAHESH”},
{102038402,”SURESH”},
{102038403,”KALPESH”},
{102038404,”RAHUL”},
{102038405,”SUBBU”},
{102038406,”RAKESH”},
{102038407,”ATUL”},
{102038408,”DHARMESH”},
{102038409,”AJAY”},
{102038410,”ABDUL”},
{102038411,”RASHMI”}
};
void main()
{

unsigned long int ENROL;
clrscr();
printf(“ENTER THE Enroll bwtn 102038400 to 8411 : “);
scanf(“%ld”,&ENROL);
if(ENROL>102038399 && ENROL<102038412)
{
printf(“\n\n\tENROLMENT NO.\t: %ld”,ENROL);
printf(“\n\tNAME\t\t: %s”,STUD[ENROL-102038400].NAME);
}
else
printf(“\nYOU HAVE ENTERED WRONG ENROLMENT NO. !!”);
getch();
}

 

Code:

#include<stdio.h>
struct student
{
unsigned long int ENROL;
char NAME[15];
}STUD[12]={
{102038400,"GANESH"},
{102038401,"MAHESH"},
{102038402,"SURESH"},
{102038403,"KALPESH"},
{102038404,"RAHUL"},
{102038405,"SUBBU"},
{102038406,"RAKESH"},
{102038407,"ATUL"},
{102038408,"DHARMESH"},
{102038409,"AJAY"},
{102038410,"ABDUL"},
{102038411,"RASHMI"}
};
void main()
{
unsigned long int ENROL;
clrscr();
printf("ENTER THE Enroll bwtn 102038400 to 8411 : ");
scanf("%ld",&ENROL);
if(ENROL>102038399 && ENROL<102038412)
{
printf("\n\n\tENROLMENT NO.\t: %ld",ENROL);
printf("\n\tNAME\t\t: %s",STUD[ENROL-102038400].NAME);
}
else
printf("\nYOU HAVE ENTERED WRONG ENROLMENT NO. !!");
getch();
}

Screen Shots:

C_program_Student_Name_Matrix

C_program_Student_Name_Matrix_Output

 

Write an algorithm and draw flowchart to find whether a given string S1 is substring of another string S2. 10m Dec2007

Write an algorithm and draw flowchart to find whether a given string S1 is substring of another string S2. 10m Dec2007

 

Algorithm

Step 1: Input String and Substring (Note: Substring should be smaller than String)

Step 2: Find Length of String (Len1) and Find Length of Substring (Len2)

Step 3: flag <- 0

Step 4: for(i=0;i<=count1-count2;i++)

{

for(j=i;j<i+count2;j++)

{

flag=1;

if (str[j]!=search[j-i])

{

flag=0;

break;

}

}

if (flag==1)

break;

}

Step 5: if (flag==1)

write(“SEARCH SUCCESSFUL!”);

else

write “SEARCH UNSUCCESSFUL!”

Step 6: Stop

 FlowChart:

FC_Find_SubString

Program Search S:-

#include<stdio.h>
#include<conio.h>
void main()
{
char str[80],search[10];
int count1=0,count2=0,i,j,flag;
clrscr();
puts(“Enter a string:”);
gets(str);
puts(“Enter search substring:”);
gets(search);
while (str[count1]!=’\0′)
count1++;
while (search[count2]!=’\0′)
count2++;
for(i=0;i<=count1-count2;i++)
{
for(j=i;j<i+count2;j++)
{
flag=1;
if (str[j]!=search[j-i])
{
flag=0;
break;
}
}
if (flag==1)
break;
}
if (flag==1)
puts(“SEARCH SUCCESSFUL!”);
else
puts(“SEARCH UNSUCCESSFUL!”);
getch();
}

#include<stdio.h>
#include<conio.h>
void main()
{
char str[80],search[10];
int count1=0,count2=0,i,j,flag;
clrscr();
puts("Enter a string:");
gets(str);
puts("Enter search substring:");
gets(search);
while (str[count1]!='\0')
count1++;
while (search[count2]!='\0')
count2++;
for(i=0;i<=count1-count2;i++)
{
for(j=i;j<i+count2;j++)
{
flag=1;
if (str[j]!=search[j-i])
{
flag=0;
break;
}
}
if (flag==1)
break;
}
if (flag==1)
puts("SEARCH SUCCESSFUL!");
else
puts("SEARCH UNSUCCESSFUL!");
getch();
}

Screen Shots:

C_program_Find_SubString

C_program_Find_SubString_Output

List and explain the precedence of Arithmetic, Logical and Relational operators in ‘C’. 10m Dec2007

List and explain the precedence of Arithmetic, Logical and Relational operators in ‘C’. 10m Dec2007

C uses a certain hierarchy to solve such kind of mixed expressions. The hierarchy and associatively of the operators discussed so far is summarized in Table. The operators written in the same line have the same priority. The higher precedence operators are written first

ARITHMETIC OPERATORS

+ Addition
- Subtraction
* Multiplication
/ Division
% Modular Division

Arithmetic operators are used for making mathematical expression and evaluating results in any kind of formulas by using Brackets wherever needed.

RELATIONAL OPERATORS

Operator Check Condition Meaning
== X==Y X is equal to Y
!= X!=Y X is not equal to Y
< X<Y X is less than Y
<= X<=Y X is less than or equal to Y
> X>Y X is greater than Y
>= X>=Y X is greater than or equal to Y

Relational operators are used to check any condition by comparing the values of variables used inside a program. The result of any comparison (condition) will give you true or false only.

LOGICAL OPERATORS

Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT

Logical operators (AND and OR) combine two conditions and logical NOT is used to negate the condition i.e. if the condition is true, NOT negates it to false and vice versa.

Write the syntax for the declaration of a function. Also discuss the parameter passing methods with an example program. 10m Dec2007

Explanation of FUNCTION:

A function is a block of code that has a name and it has a property that it is reusable i.e. it can be executed from as many different points in a C Program as required.

Function groups a number of program statements into a unit and gives it a name. This unit can be invoked from other parts of a program. A computer program cannot handle all the tasks by itself. Instead its requests other program like entities – called functions in C – to get its tasks done. A function is a self contained block of statements that perform a coherent task of same kind.

The name of the function is unique in a C Program and is Global. It means that a function can be accessed from any location within a C Program. We pass information to the function called arguments specified when the function is called. And the function either returns some value to the point it was called from or returns nothing.

We can divide a long C program into small blocks which can perform a certain task. A function is a self contained block of statements that perform a coherent task of same kind.

 

Recursive function is a function which calls itself. Calling a function within itself makes it a endless loop. So we need to take care that there must be a termination condition in every recursive function.

For writing a function and using it in the C program, we should declare the function in the MAIN function. Declaration has to done in the area before the code starts, same area where we declare data variables.

int factorial(int);

Function returns value and the ones which does not return any value is called and declared as void. This function which we are writing returns the factorial in decimal form as output. The values inside the round brackets are called Arguments. The Argument and return type are integer type. A function can return only one value so we have to take only one data type in which its value is expected.

Let’s discuss the parameter passing methods with an example program of Factorial program.

First variables will be the one which will save the value entered by the user NUM. Other variable will be FACT which will be for holding the resultant factorial value returned by the FUNCTION. The identified variables are FACT,NUM.

Now, Selection of data type is int data type due to the values expected are decimals and they will be holding smaller values so int data type is sufficient.

Main program needs only declaration of variables and function prototype. Also messages for user and scanning values  NUM and FACT is used to display the resultant values returned by the FUNCTION.

#include<stdio.h>
void main()
{
 int factorial(int);
 int FACT,NUM;
 printf("ENTER NUMBER : ");
 scanf("%d",&NUM);
 FACT=factorial(NUM);
 printf("\nFACTORIAL OF GIVEN NUMBER IS %d ",FACT);
 getch();
}

Let’s identify variables needed for function which is part of program outside main function.
Variables which are passed in the function may not be declared again which is N.  NUM is passed to the function and saved in N variable of the function. Now the variable RESULT which will hold the resultant value to be returned by the FUNCTION. Variable.  The identified variable is RESULT.

Now, Selection of data type is int data type due to the values expected are decimals and they will be holding smaller values so int data type is sufficient.

int RESULT;

In this program there is a risk of generating an ENDLESS LOOP. Here we have to Check the TERMINATION condition is given or not. N is the given value it is reduced by one in the recursive function call as we have to multiply all the number from given N to 1. Their must stop at N equals 1, and if user enters value 1 then the result is also 1, hence we should return 1 in if condition and recursion in else condition. Return the Result at the end.

int factorial(int N)
{
 int RESULT;
    if(N==1)
    return(1);
    else
    RESULT=N*factorial(N-1);
 return(RESULT);
}

Steps of function call :-

RESULT=0   & N=5, RESULT = 5 * factorial(4), hence RESULT=5
RESULT=5   & N=4, RESULT = 4 * factorial(3), hence RESULT=20
RESULT=20  & N=3, RESULT = 3 * factorial(2), hence RESULT=60
RESULT=60  & N=2, RESULT = 2 * factorial(1), hence RESULT=120
RESULT=120  & N=1, RESULT = 1 * 1, hence RESULT=120

Note:- Remember whenever you are calling a function which is returning a value it should always be assigned to a variable of same data type or called inside the printf function as variable.

C program code :

  1. #include<stdio.h>
  2. void main()
  3. {
  4.  int factorial(int);
  5.  int FACT,NUM;
  6.  printf("ENTER NUMBER : ");
  7.  scanf("%d",&NUM);
  8.  FACT=factorial(NUM);
  9.  printf("\nFACTORIAL OF GIVEN NUMBER IS %d ",FACT);
  10.  getch();
  11. }
  12.  
  13. int factorial(int N)
  14. {
  15.  int RESULT;
  16.     if(N==1)
  17.     return(1);
  18.     else
  19.     RESULT=N*factorial(N-1);
  20.  return(RESULT);
  21. }

Screen Shots :-

C_program_Factorial_Recursion

C_program_Factorial_Recursion_Output

Write a recursive function in ‘C’ that computes the factorial of a given integer. 10m Dec2007

Solved program can be found on this link http://cssimplified.com/c-programming/a-c-program-to-find-the-factorial-of-a-number-using-recursion

Design an algorithm, draw a corresponding flow chart and write a ‘C’ program for Binary Search, to search a given number among the list of numbers. 10m Dec2007

Design an algorithm, draw a corresponding flow chart and write a ‘C’ program for Binary Search, to search a given number among the list of numbers. 10m Dec2007

 

Algorithm

Step 1: Declare an array ‘k’ of size ‘n’ i.e. k(n) is an array which stores all the keys of a file containing ‘n’ records

Step 2: I <– 0

Step 3: low<–0, high <– n-1

Step 4: while (low <= high)do

mid = (low + high)/2

if (key=k[mid]) then

write “record is at position”, mid+1 //as the array starts from the 0th position

else

if(key < k[mid]) then

high = mid – 1

else

low = mid + 1

endif

endif

endwhile

Step 5: Write “Sorry, key value not found”

Step 6: Stop

 FlowChart:

FC_Binary_Search

Program Binary Search:-

#include<stdio.h>
void main()
{
int NUM[10]={0,1,2,3,4,5,6,7,8,9};
int LOW=0,HIGH=9,KEY,MID,FLAG=0;
clrscr();
printf(“ENTER KEY NUMBERS BTWN (0-9)\n”);
scanf(“%d”,&KEY);
do
{
MID=(LOW+HIGH)/2;
if(KEY==NUM[MID])
{
printf(“\nKEY FOUND AT %d POSITION\n”,MID+1);
FLAG=1;
}
else
{
if(KEY<NUM[MID])
HIGH=MID-1;
else
LOW=MID+1;
}
}while(LOW <= HIGH && FLAG == 0);
if(FLAG == 0)
printf(“\nSORRY KEY VALUE NOT FOUND\n”);
getch();
}

#include<stdio.h>
void main()
{
int NUM[10]={0,1,2,3,4,5,6,7,8,9};
int LOW=0,HIGH=9,KEY,MID,FLAG=0;
clrscr();
printf("ENTER KEY NUMBERS BTWN (0-9)\n");
scanf("%d",&KEY);
do
{
MID=(LOW+HIGH)/2;
if(KEY==NUM[MID])
{
printf("\nKEY FOUND AT %d POSITION\n",MID+1);
FLAG=1;
}
else
{
if(KEY<NUM[MID])
HIGH=MID-1;
else
LOW=MID+1;
}
}while(LOW <= HIGH && FLAG == 0);
if(FLAG == 0)
printf("\nSORRY KEY VALUE NOT FOUND\n");
getch();
}

Screen Shots:

C_program_Binary_Search

C_program_Binary_Search_Output

 

Give the Excitation tables and Block diagrams for the following: 10m Jun2007

Give the Excitation tables and Block diagrams for the following: 10m Jun2007

(i)                 D flip-flop

(ii)               T flip-flop

 

D Flip-Flop:

The D flip-flop shown in Figure is a modification of the clocked SR flip-flop. The D input goes directly into the S input and the complement of the D input goes to the R input. The D input is sampled during the occurrence of a clock pulse. If it is 1, the flip-flop is switched to the set state (unless it was already set). If it is 0, the flip-flop switches to the clear state.

D_Flip-Flop

T Flip-Flop:

The T flip-flop is a single input version of the JK flip-flop. As shown in Figure, the T flip-flop is obtained from the JK type if both inputs are tied together. The output of the T flip-flop “toggles” with each clock pulse.

T_Flip-Flop

 

Write an assembly program to concatenate two strings of size 3 characters and explain its logic. 10m Jun2007

Solved program can be found on this link http://cssimplified.com/computer-organisation-and-assembly-language-programming/an-assembly-lanuage-program-which-takes-two-inputs-as-strings-and-display-the-concatenated-string

Explain the following:  5×4=20

  • Flash memory

Refer: – MCS-012 Block 2 page 11

 

  • Direct Memory Access (DMA)

Refer: – MCS-012 Block 2 page 56 and 57

 

  • Jaz drive

Refer: – MCS-012 Block 2 page 75

 

  • Instruction pipelining

Refer: – MCS-012 Block 3 page 48 and 49

 

  • Hardwired control organization

Refer: – MCS-012 Block 3 page 71 and 72

Explain the basic principle of Quine-McCluskey method of simplifying the Boolean expression with the help of an example function. 6m Jun2007

Explain the basic principle of Quine-McCluskey method of simplifying the Boolean expression with the help of an example function. 6m Jun2007

Quine McKluskey Method

A tabular method was suggested to deal with the increasing number of variables known as Quine McKluskey Method. This method is suitable for programming and hence provides a tool for automating design in the form of minimizing Boolean expression.

The basic principle behind the Quine McKluskey Method is to remove the terms, which are redundant and can be obtained by other terms.

To understand Quine – Mc Kluskey method lets us see following example:-

EQ1

Step I: The terms of the function are placed in table as follows:

Step1

Step II: Forming the pairs which differ in only one variable also put check (v) against the terms selected and finding resultant terms as follows :-

Step2

Step III: Now, constructing final table as:

Step3

Thus all columns have mark ‘X’. Thus the final expression is:

EQ2

The process can be summarized as follows:-

Step I: Build a table in which each term of the expression is represented in row (Expression should be in SOP form). The terms can be represented in the 0 (Complemented) or 1 (normal) form.

Step II: Check all the terms that differ in only one variable and then combine the pairs by removing the variable that differs in those terms. Thus a new table is formed. This process is repeated, if necessary, in the new table also until all uncommon terms are left i.e. no matches left in table.

Step III:

a) Finally, a two dimensional table is formed all terms which are not eliminated in the table form rows and all original terms form the column.

b) At each intersection of row and column where row term is subset of column term, an ‘X’ is placed.

Step IV:

a) Put a square around each ‘X’ which is alone in column

b) Put a circle around each ‘X’ in any row which contains a squared ‘X’

c) If every column has a squared or circled ‘X’ then the process is complete and the corresponding minimal expression is formed by all row terms which have marked Xs.

 

Design and draw the 4-bit adder-subtractor circuit using full adders and XOR gates. Explain its working in brief. 5m Jun2007

Solved Answer can be found on this link http://cssimplified.com/computer-organisation-and-assembly-language-programming/draw-the-logic-diagram-of-a-full-adder-create-a-2-bit-adder-subtractor-circuit-using-the-block-diagram-of-the-full-adder-6m-jun2007