IP Prefinal-4
IP Prefinal-4
Instructions:
1. Answer all the questions from Part-A. Each question carries Two mark.
2. Answer one full question from each unit in Part-B. Each full question carries 10 marks
-----------------------------------------------------------------------------------------------------------------
PART- A
1 a Define compiler 1 CO1 [2M]
PART- B
2 a Explain the generations of computers. 2 CO1 [5M]
b What is type casting (Type conversion)? Explain different typesof type 1 CO1 [5M]
conversions with example?
OR
3 a Define Flowchart? Draw and explain different symbols used in flowchart 2 CO1 [5M]
with example?
b Explain the basic organization of a computer with a neat diagram 2 CO1 [5M]
OR
5 a Write a C program to given number is Armstrong number or not? 3 CO2 [5M]
b Write a c program to find length of string without using strlen() function. 2 CO3 [5M]
OR
7 a Write a c program to find multiplication of arrays. 2 CO3 [5M]
8 a How to declare and initialize structures? Explain with examples 3 CO4 [5M]
OR
9 a Write a program to copy string using pointers? 2 CO4 [5M]
OR
1 a Write a c program to copy the content of one file to another. 3 CO5 [5M]
1
b Explain call by reference with example. 2 CO5 [5M]
*****
SCHEME OF VALUATION
PART-B
Mar
Q. Sub ks
Detailed Key & Scheme of valuation
No Q.No allott
ed
2. a) 5M
Generations of
Computer Time-Period Evolving Hardware
Each
First gener
1940s – 1950s Vacuum Tube Based
Generation ation
1M
Second
1950s – 1960s Transistor Based 5*1=
Generation
5M
Third
1960s – 1970s Integrated Circuit Based
Generation
Fourth
1970s – Present Microprocessor Based
Generation
Fifth
Present – Future Artificial Intelligence Based
Generation
Syntax/Declaration:- Each
type
destination_datatype = (target_datatype)variable; carri
es
In C programming, we can convert the value of one data type (int, float, 2M
double, etc.) to another. This process is known as type conversion. 2*2=
4M
This type of conversion is known as implicit type conversion. In C, there
are two types of type conversion:
Implicit Conversion
Explicit Conversion
Example:
#include<stdio.h>
int main()
return 0;
Output:
Double Value: 4150.12
Example:
#include<stdio.h>
int main()
return 0;
Output:
Integer Value: 35
1. Input Unit: The input unit is used to feed any form of data to the
computer.
The CPU has three components which are the Control unit, the
Arithmetic, and logic unit (ALU), and the Memory unit.
3. Arithmetic and Logic Unit: The ALU is a part of the CPU where
various computing functions are performed on data. The ALU performs
arithmetic operations such as addition, subtraction, multiplication,
division, and logical operations.
4. Control Unit: The control unit controls the flow of data between the
CPU, memory, and I/O devices. It also controls the entire operation of a
computer.
6. Memory Unit: The Memory Unit is of two types which are primary
memory and secondary memory. The primary memory is used to
temporarily store the programs and data when the instructions are ready
to execute. The secondary memory is use to store the data permanently.
The primary memory is volatitle, that is the content is lost when the
power supply is switched off. The Random Access Memory (RAM) is an
example of the main memory.
The data type specifies the type of element that will be contained in the
array, such as int, float, or char or any valid data type.
The size indicates the maximum number of elements that can be stored
inside the array.
Program:
#include <stdio.h>
int main()
return 0;
Output:
numbers[0] = 10
numbers[1] = 20
numbers[2] = 30
numbers[3] = 40
numbers[4] = 50
b) #include <stdio.h> 5M
int main() {
char s[] = "Programming is fun"; Decl
int i; arati
on
for (i = 0; s[i] != '\0'; ++i); 1M
Outp
ut
1M
7. a) #include<stdio.h> 5M
#include<stdlib.h> Decl
int main(){ arati
on
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;
1M
system("cls");
printf("enter the number of row=");
scanf("%d",&r);
Intial
printf("enter the number of column="); izatio
scanf("%d",&c); n 1M
printf("enter the first matrix element=\n");
for(i=0;i<r;i++) Multi
{ plicat
ion
for(j=0;j<c;j++) Logi
{ c 2M
scanf("%d",&a[i][j]);
} Outp
} ut
1M
printf("enter the second matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("multiply of the matrix=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
//for printing result
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",mul[i][j]);
}
printf("\n");
}
return 0;
}
b) 5M
1. strcat() Function
4. strcpy
b) Pointer arithmetic: 5M
• There are a few very limited mathematical operations that may
be performed on address data types, i.e. pointer variables. Each
• Most commonly, integers may be added to or subtracted from opera
addresses. tion
Operation Declaration Usage carri
es
1M
Assignment Int *p1,*p2 p1=p2(both should be
same type )
5*1=
Addition of integer Int I,*ptr; Ptr+I 5M
b) Function Declaration: 5M
A function declaration defines the name and return type of a function in a
program. Before using the function, we need to declare it outside of a Defi
main() function in a program. nitio
n 1M
Syntax:
return_data_type function_name ( data_type arguments) ;
Synt
Function Calling: x=1
Exa
A function call is an important part of the C programming language. It is mple
called inside a program whenever it is required to call a function. It is
only called by its name in the main() function of a program. We can pass =3
the parameters to a function calling in the main() function.
Syntax: Add(a, b) // a and b are the parameters
Example:
#include <stdio.h>
int add(int a, int b);
void main()
{
int sum;
int a, b;
printf(" Enter the first and second number \n");
scanf("%d %d", &a, &b);
sum = add(a, b); // call add() function
printf( "The sum of the two number is %d", sum);
}
int add(int n1, int n2) // pass n1 and n2 parameter
{
int c;
c = n1 + n2;
return c;
}
Output:
Enter the first and second number
5
6
The sum of the two number is 11
11. a) #include <stdio.h> 5M
#include <stdlib.h> // For exit()
int main(){ Decl
FILE *fptr1, *fptr2; arati
char filename[100], c; on
printf("Enter the filename to open for reading and
"); crati
scanf("%s",filename); ng a
// Open one file for reading file
fptr1 = fopen(filename, "r"); 2M
if (fptr1 == NULL){
printf("Cannot open file %s ", filename);
exit(0); Copy
} ing
printf("Enter the filename to open for writing conte
"); nt
scanf("%s", filename); 2M
// Open another file for writing
fptr2 = fopen(filename, "w"); Closi
if (fptr2 == NULL){ ng
printf("Cannot open file %s ", filename); files
exit(0); 1M
}
// Read contents from file
c = fgetc(fptr1);
while (c != EOF){
fputc(c, fptr2);
c = fgetc(fptr1);
}
printf("
Contents copied to %s", filename);
fclose(fptr1);
fclose(fptr2);
return 0;
}
b) 5M
In call by reference, the address of the variable is passed into the
function call as the actual parameter. Defi
The value of the actual parameters can be modified by changing nitio
n
the formal parameters since the address of the actual parameters is 2M
passed.
In call by reference, the memory allocation is similar for both
formal parameters and actual parameters. All the operations in the
function are performed on the value stored at the address of the
actual parameters, and the modified value gets stored at the same
Progr
address. am
3M
#include<stdio.h>
void change(int *num) {
printf("Before adding value inside function num=%d \n",*num);
(*num) += 100;
printf("After adding value inside function num=%d \n", *num);
}
int main() {
int x=100;
printf("Before function call x=%d \n", x);
change(&x);//passing reference in function
printf("After function call x=%d \n", x);
return 0;
}