2079 Regular
2079 Regular
A language processor, or translator, is a computer program that translates source code from one
programming language to another. They also identify errors during translation. There are three types
of language processors: assembler, compiler, and interpreter.
3. Assembler
The assembler translates a program written in assembly language into machine code.
Assembly language is a low-level, machine-dependent symbolic code that consists of instructions (like
ADD, SUB, MUX, MOV, etc.).
4. Compiler
A compiler reads an entire source code and then translates it into machine code. Further, the machine
code, aka the object code, is stored in an object file.
If the compiler encounters any errors during the compilation process, it continues to read the source
code to the end and then shows the errors and their line numbers to the user.
Compiled programming languages are high-level and machine-independent. Moreover, examples of
compiled programming languages are C, C++, C#, Java, Rust, and Go.
5. Interpreter
An interpreter receives the source code and then reads it line by line, translating each line of code to
machine code and executing it before moving on to the next line.
If the interpreter encounters any errors during its process, it stops the process and shows an error
message to the user.
Interpreted programming languages are also high-level and machine-independent. Python, Javascript,
PHP, and Ruby are examples of interpreted programming languages.
b)
1. Problem Analysis
2. Program Design - Algorithm, Flowchart and Pseudocode
3. Coding
4. Compilation and Execution
5. Debugging and Testing
6. Program Documentation
Algorithm
Step 1 : Start
Step 2 : Assign sum=0 and i=0
Step 8 : Stop
flowchart
2)a)
Formatted I/O in C
The I/O procedure is known as "formatted I/O". It enables you to read or write data in a certain
format. Printf() and scanf() are two examples of C routines that handle formatted I/O. The type and
format of the data to be read or written are specified by format strings, which are used by these
operations. The program's execution replaces the placeholders for the data found in the format strings
with the actual data.
Unformatted I/O in C
Unformatted I/O refers to a category of I/O operations that reads or writes data as a stream
of bytes without regard to any format. Unformatted I/O in C is carried out with the aid of functions
like fread() and fwrite(). Without formatting, these operations are used to read and write data directly
to and from files.
getch():
getch() function reads a single character from the keyboard by the user but doesn’t display that
character on the console screen and immediately returned without pressing enter key. This function is
declared in conio.h(header file). getch() is also used for hold the screen.
getche():
getche() function reads a single character from the keyboard by the user and displays it on the console
screen and immediately returns without pressing the enter key. This function is declared in
conio.h(header file).
getchar():
The getchar() function is used to read only a first single character from the keyboard whether multiple
characters is typed by the user and this function reads one character at one time until and unless the
enter key is pressed. This function is declared in stdio.h(header file)
b)
expression in C is defined as 2 or more operands are connected by one operator and which can also be
said to a formula to perform any operation. An operand is a function reference, an array element, a
variable, or any constant
#include<stdio.h>
void main()
{
int a,b,small;
printf("Enter two number\n");
scanf("%d %d",&a,&b);
small = a<b?a:b;
printf("Smallest among 2 Number is : %d",small);
3)a)
b)
#include <stdio.h>
#include<conio.h>
#include<math.h>
double sum=1,term=1,fct,j,y=2,m;
int i;
for(i=1;i<n;i++)
fct=1;
for(j=1;j<=y;j++)
{
fct=fct*j;
term=term*(-1);
m=term*pow(x,y)/fct;
sum=sum+m;
y+=2;
return sum;
int main()
{double x=9;
int n=10;
printf("%.4f",series(x,n));
return 0;}
4)a)
1. Library Function
A library function is also referred to as a “built-in function”. A compiler package already exists that
contains these functions, each of which has a specific meaning and is included in the package. Built-in
functions have the advantage of being directly usable without being defined, whereas user-defined
functions must be declared and defined before being used.
b)
5)
char name[5][10];
#include <stdio.h>
void enterData(int firstMatrix[][10], int secondMatrix[][10], int rowFirst, int columnFirst, int rowSecond,
int columnSecond);
void multiplyMatrices(int firstMatrix[][10], int secondMatrix[][10], int multResult[][10], int rowFirst, int
columnFirst, int rowSecond, int columnSecond);
void display(int mult[][10], int rowFirst, int columnSecond);
int main()
{
int firstMatrix[10][10], secondMatrix[10][10], mult[10][10], rowFirst, columnFirst, rowSecond,
columnSecond, i, j, k;
return 0;
}
void enterData(int firstMatrix[][10], int secondMatrix[][10], int rowFirst, int columnFirst, int rowSecond,
int columnSecond)
{
int i, j;
printf("\nEnter elements of matrix 1:\n");
for(i = 0; i < rowFirst; ++i)
{
for(j = 0; j < columnFirst; ++j)
{
printf("Enter elements a%d%d: ", i + 1, j + 1);
scanf("%d", &firstMatrix[i][j]);
}
}
6)a)
Structures (also called structs) are a way to group several related variables into one place. Each variable
in the structure is known as a member of the structure. Unlike an array, a structure can contain many
different data types (int, float, char, etc.).
Structure in C programming is very helpful in cases where we need to store similar data of multiple
entities. Let us understand the need for structures with a real-life example. Suppose you need to
manage the record of books in a library. Now a book can have properties like book_name, author_name,
and genre.
b)
#include<stdio.h>
int main()
{
int a, b;
swap(&a, &b);
return 0;
}
temp = *x;
*x = *y;
*y = temp;
}
7)a)
fputc():
fputc() is used to write characters to the file.
Syntax:
type fputc(‘character’,file_pointer);
fputs():
fputs() is used to write a null-terminated string to the file.
Syntax:
fputs(“string”,file_pointer);
fgetc():
fgetc() works exactly the opposite of fputc(). It reads the character from the file.
Syntax:
type = fgetc(file_pointer);
fgets():
fgets() is used to read a string from a file.
Syntax:
int fgets(const char *s, int n, file_pointer);
b)
#include<stdio.h>
#include<string.h>
typedef struct
{
char name[30];
int salary;
int age;
}employee;
int main()
{
employee e[20], temp;
int i,j,n;
printf("Enter n:\n");
scanf("%d",&n);
for(i=0;i< n;i++)
{
printf("Enter name, salary and age of employee:\n");
scanf("%s%d%d",e[i].name, &e[i].salary, &e[i].age);
}
for(i=0;i< n-1;i++)
{
for(j=i+1;j< n;j++)
{
if(strcmp(e[i].name, e[j].name) > 0)
{
temp = e[i];
e[i] = e[j];
e[j] = temp;
}
}
}
printf("Records in alphabetical order are:\n");
for(i=0;i< n;i++)
{
printf("Name: %s\n", e[i].name);
printf("Salary: %d\n", e[i].salary);
printf("Age: %d\n\n", e[i].age);
}
return 0;
}
8)b)
program sorting
integer marks (10), i, j, temp
write(*,*) 'Enter marks of ten students:'
read (*,*) (marks (i),i=1,10)
do i=1,9
do j=i+1,10
if (marks (i) .lt. marks (j)) thentemp=marks (i)
marks (i) =marks (j)
marks (j)=temp
endif
enddo
enddo
write(*,*) 'The second highest mark is:
write(*,*) marks (2)
end
a)