Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

THEORY OF COMPUTATION LABORATORY 1

LAB MANUAL
(CS-501)

V Sem (CSE)

CHAMELI DEVI GROUP OF


INSTITUTIONS, INDORE

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF COMPUTER SCIENCE & ENGG
THEORY OF COMPUTATION LABORATORY 2

CHAMELI DEVI GROUP OF INSTITUTIONS


INDORE (M.P.)

DEPARTMENT OF
Computer Science & Engg

CERTIFICATE

This is to certify that Mr./Ms……………………………………………………………… with RGPV

Enrollment No. 0832 ..…………………………..has satisfactorily completed the course of experiments in

Theory of Computation laboratory, as prescribed by Rajiv Gandhi Proudhyogiki Vishwavidhyalaya, Bhopal

for V Semester of the Computer Science & Engg Department during year 2019 20

Signature of
Faculty In-charge

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF COMPUTER SCIENCE & ENGG
THEORY OF COMPUTATION LABORATORY 3

INDEX
Sl. Expt. Name of the Experiment Date Signature
No. No. of of Faculty-
Condu in-Charge
ction
01. 3 Design a Program for Mode 3 Machine
02. 4 Design a program for accepting decimal number divisible by 2.

EXPT. No 3. - Design a Program for Mode 3 Machine.

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF COMPUTER SCIENCE & ENGG
THEORY OF COMPUTATION LABORATORY 4
Aim: Design a Program for Mode 3 Machine

Theory: Given two numbers ‘num’ and ‘divisor’, find remainder when ‘num’ is divided by ‘divisor’. The use of
modulo or % operator is not allowed.
Examples:
 Input: num = 100, divisor = 7
Output: 2
 Input: num = 30, divisor = 9
Output: 3

Viva Questions:
1. Define Automata/FSM?
2. What is the application of Finite Automata?
3. Design FSM for Mod 3?
4. What are the characteristics of Automata?

Solution:

C++ program to find remainder without using


// modulo operator
#include <iostream>
using namespace std;

// This function returns remainder of num/divisor


// without using % (modulo) operator
int getRemainder(int num, int divisor)
{
return (num - divisor * (num / divisor));
}

// Driver program to test above functions


int main()
{
// cout << 100 %0;
cout << getRemainder(100, 7);
return 0;
}

EXPT. No.- 4. Design a program for accepting decimal number divisible by 2.

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF COMPUTER SCIENCE & ENGG
THEORY OF COMPUTATION LABORATORY 5
Aim: Design a program for accepting decimal number divisible by 2.

Theory: In this program user checks the logic about numeric value that will it be Division able with 5 or not. To
check this declares a variable of integer type. And a logic will be used along with the Modulus operator(%).that
will be manipulate with the numeric value and control statement (if-else) used if the numeric value is dividable
than output will be ok else it will be reverse.
Problem Statement:
This is the program to check whether the Numeric value is division able with 2 or Not.
 Enter Numeric value.
 Use Logic to manipulate.
 Declare if-else Condition.
 Displaying output on the Display.
Here is source code of the C program to Check out The Numeric value is Division able with 2 or Not.
Viva Questions:
1. Define string created by using alphabet?
2. How to design the automata to check weather decimal divisible by any number?
3. How the string is accepted by the Automata?
4. Difference between DFA and NDFA?

Solution:
#include<stdio.h>
void main()
{
int a;
clrscr();
printf ("Enter the no.");
scanf("%d",&a);
if(a%5==0)
{
printf("Accept: No.is Divisible by 2");
}
else
{
printf("Reject: No is not Divisible by 2");
}
getch();
}

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF COMPUTER SCIENCE & ENGG

You might also like