You are on page 1of 38

How to Answer a Question.?!

What Would be the Expected Answer.?!


How to get Maximum marks in VTU Valuation.?!

Solution to
Model Question Paper-1
Problem Solving Through Programming
WELCOME
Let us

EXPLORE ELECTRONICS
Do Subscribe

EXPLORE ELECTRONICS

Click for PSP videos:


https://youtube.com/playlist?list=PLu7-Sp50sShcBHqHjJL0Lnf_R6JXZQ5ss
Click here
For Videos
First-generation computers:
•First-generation computers (1940-1958) Minimum 5 points each
•They used vacuum tubes for circuitry and magnetic drums for memory
Explanation
•They were big in size and each computer used to occupy the entire room space
•They were very expensive and used to consume a lot of electricity 8M
•The programmers used to write programs only in machine language to perform various operations.
•They used to solve only one problem at a given time
•Some of the examples are UNIVAC-I (UNIVersal Automatic Computer),
•ENIAC (Electronic Numerical Integrator And Calculator) etc.
SecondGeneration:
Write two to
•The transistors were the most important component which replaced vacuum tubes.
three lines of
•Magnetic cores were used for memory.
Explanation for
•It was more reliable than first-generation computer.
these points
•The assembly or symbolic language was used.
•The input and output mechanisms remained the same.
•The stored program concept was introduced which stores both data and program.
Third Generation:
•The Integrated circuits(IC) were the most important component.
•The transistors, diodes, resistors, and capacitors were integrated on a single chip.
•The high-level language was used like BASIC, C, C++, and JAVA.
•Memory capacity increased and a magnetic hard disk was used for the second generation.
•The third generation computers also had OS and computers could rum programs invoked by multi-users.
EXPLORE ELECTRONICS
Click here
For Videos
Fourth Generation:
•The Microprocessor was the most important component.
•With the help of LSI (Large Scale Integration) and VLSI (Very Large Scale Integration), the entire CPU is on a single
chip.
•OS has moved from MSDOS to GUI (Graphical User Interface) like windows.
•The networking technology has also been improved.
•The size was reduced and the speed was increased.
Fifth Generation:
•Artificial Intelligence and the use of natural languages are the main features of this generation.
•These systems are expected to interact with users in natural language.
•Speech recognition and speech output should also be possible.
•Computers are must be able to perform parallel processing.
•The quad-core and octa-core were also introduced.
•Neural networks and expert systems have been developed.
Click here
For Videos

Explanation with example


5M

1.Bit:-
The data are represented by the state of electronic switches. A switch with
ON state represents 1 and OFF state represents 0 (zero). These values which represent the state of a switch are called bits.
Example:-
In other words, the binary digits 1 and 0 are called bits. Thus, a bit is the smallest unit of data.
2. Nibble:-
Definition: A group of 4 bits (a half byte) is called a nibble or 1⁄2 byte.
Example:
An integer 9 can be represented using a nibble as shown below:
1001= nibble
3. Byte:-
A group of 8 bits is called a byte.
A byte is the smallest unit of data that can be manipulated by a computer at any given time. After accessing a byte, the bits
or nibbles can be manipulated.
Click here
For Videos

4. Word:-

A word is the unit of information in which information may be stored, transmitted, or operated within a given
computer.
1 word = 16 bits (or 2 bytes)

5. Kilobyte:-

1 Kilobyte = 1024 bytes


1 Megabyte = 1024 Kilobytes
Click here
For Videos

Primary Memory:-
•The memory that is accessible directly by the CPU of a computer is called primary memory.
•This memory is part of the main computer system which is plugged into the motherboard along with the CPU.
•Hence, this memory is also called internal memory or main memory.
•This primary memory allows the CPU to store and retrieve data quickly.
The primary memory is divided into the following types:
•Random Access Memory (RAM): SRAM and DRAM
•Read Only Memory (ROM, PROM, EPROM, EEPROM)
•Cache memory (L1, L2 and L3)
•CPU registers
Secondary Memory:-
•The memory that is not part of the computer’s main memory and which is not directly connected to the CPU but connected to the motherboard
through ports and connectors is called secondary memory.
•In secondary memory, we can store all the data and programs permanently and can be moved from one place to another place and can be
connected to another computer.
•The secondary memory is also called auxiliary memory.
•The data and instructions are loaded from secondary memory to main memory so that the CPU can process the data.
•Ex: floppy diskette, hard disk, CD-ROMs, magnetic tapes, Blu-ray disk, flash memory (Pen drive), etc.
•The different types of storage devices are shown below:
•Floppy disk (1.2MB and 1.44MB) which is obsolete
•Hard disk (500GB to 4TB)
•Magnetic Tape (20TB)
•Optical discs: CD-ROM, DVD-ROM, Blue-Ray Disk
•Flash memory
Click here
For Videos

In C programming, an enumeration type (enum) is a data type that consists of integral constants.

To define enums, the enum keyword is used.


enum flag {const1, const2, ..., constN};

By default, const1 is 0, const2 is 1 and so on.


Click here
For Videos

Identifiers represent the name in the C program, for example, variables, functions, arrays, structures, unions,
labels, etc.

Rules for forming identifier names:-


1.Identifier should contain only alphabets (A-Z), (a-z), numerals(0-9) and underscore (_)
2.The identifier should start with alphabet or underscore, but not a numeric character
3.The first 31 characters in an identifier are significant, the rest of characters are neglected
4.No reserve words (keywords) of C language can be used as identifiers
5.Identifiers are case sensitive

Examples of valid identifiers:-


food, counter_7, max_1, min_1

Examples of Invalid identifiers:-


$num //$ is special character
int //keyword
name 1 //space not allowed
Click here
For Videos

#include<stdio.h>

int main() {
float radius, area;

printf("\nEnter the radius of Circle : "); https://www.youtube.com/watch?v=BLQTNdCWBgI


scanf("%d", &radius);

area = 3.14 * radius * radius;


printf("\nArea of Circle : %f", area);

return (0);
}
Click here
For Videos

One similarity between while and for loop is that they both are entry
controlled loops i.e. they both will check the condition for true or false. If the
condition is true then only the entry within the loop is permitted

https://www.youtube.com/watch?v=aBPhdHD0Ykc
Click here
For Videos

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,m;
clrscr();
printf("\n Enter lower limit and upper limit");
scanf("%d%d", &m, &n);
printf("\n Numbers from %d to %d are \n", m, n);
for(i=m; i<=n; i++)
printf("%5d",i);
getch();
}

Output:
Enter lower limit and upper limit
10 20
Numbers from 10 to 20 are
10 11 12 13 14 15 16 17 18 19 20
Click here
For Videos

https://www.youtube.com/watch?v
=aBPhdHD0Ykc
Click here
For Videos

#include < stdio.h >


long factorial(int);
int main()
{
int i, n, c;
printf("Enter the number of rows you wish to see in pascal triangle\n");
scanf("%d", & n);
for (i = 0; i < n; i++) {
for (c = 0; c <= (n - i - 2); c++)
printf(" ");
for (c = 0; c <= i; c++)
printf("%ld ", factorial(i) / (factorial(c) * factorial(i - c)));
printf("\n");
}
return 0;
}
long factorial(int n) {
int c;
long result = 1;
for (c = 1; c <= n; c++) result = result * c;
return result;
}
Click here
For Videos

https://www.youtube.com/watch?v=sF4Z6lg3ldU

https://www.youtube.com/watch?v=nTbqeNByA78
Click here
For Videos
Click here
For Videos

https://www.youtube.com/watch?v=Y-NopiWOrHo
Click here
For Videos
Click here
For Videos
 “String is a variable-length data stored in a character array”.
 A string is a sequence of elements of the char data type.
 As strings are variable-size data we have to represent them using character Arrays.

#include<stdio.h>
#include<string.h>
main(){
char s1[10],s2[10],s3[10]; output:-
printf("Enter String 1\n"); Enter String 1
gets(s1); abcd
printf("Enter String 2\n"); Enter String 2
gets(s2); efgh
printf("Before Swapping\n"); Before Swapping
printf("String 1 : %s\n",s1); String 1: abcd
printf("String 2 : %s\n",s2); String 2: efgh
strcpy(s3,s1); After Swapping:
strcpy(s1,s2); String 1: efgh
strcpy(s2,s3); String 2: abcd
printf("After Swapping:\n");
printf("String 1 : %s\n",s1);
printf("String 2 : %s\n",s2);
}
Click here
For Videos
#include<stdio.h>
void main()
{
int a[10], n, i, j, temp;
printf("Enter the number of elements\n");
scanf("%d", &n);
printf("Enter the array elements\n");
for(i=0; i<n; i++)
scanf("%d", &a[i]);
for(j=1; j<n;j++) https://www.youtube.com/watch?v=XtP00_rzUuk
{
for(i=0;i<n;i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}}}
printf("The sorted array is\t");
for(i=0; i<n;i++)
printf(“%d\t”,a[i]);
}
Click here
For Videos

Ex: char str1[ ] = “america” ;


char str2[]= “india” ;
strcpy ( str1, str2 ) ;
strcpy(america,india);
america = 7character
india = 5 character

so first 5 character of america is replaced .

Output is inidaca

int strcmp(string 1, string 2);


Example: char mystr_a[10] = “Hello”;
char mystr_b[10] = “Goodbye”;
– mystr_a == mystr_b; /* NOT allowed! The
correct way is if (strcmp(mystr_a, mystr_b )) */
printf (“Strings are NOT the same.”);
else
printf( “Strings are the same.”); Here it will check
the ASCII value of H and G i.e, 72 and 71
and return the diference 1.
Click here
For Videos

 The Null character in the C programming language is used to terminate the


character strings.
 In other words, the Null character is used to represent the end of the string or
end of an array or other concepts in C.
 The end of the character string or the NULL byte is represented by '0' or '\0' or
simply NULL
Click here
For Videos
C allows you to define functions according to your need.
These functions are known as user-defined functions.

For example: Add two integers.


To perform this task, we have created an user-defined function addNumbers()
#include <stdio.h>
Different types of user-defined functions: int addNumbers(int a, int b); // function prototype
int main()
A function, depending on whether arguments {
are present or not and whether a value is int n1,n2,sum;
returned or not, may belong to one of the printf("Enters two numbers: ");
following categories. scanf("%d %d",&n1,&n2);
sum = addNumbers(n1, n2); // function call
Category I: Functions with no arguments and printf("sum = %d",sum);
no return values return 0;
Category 2: Functions with no arguments and }
with return values int addNumbers(int a, int b) // function definition
Category 3: Functions with arguments and no {
return values int result;
Category 4: Functions with arguments and result = a+b;
with return values return result; // return statement
}
Click here
For Videos

https://www.youtube.com/watch?v=ndT0gSvCXBc
Click here
For Videos
Call by Value is a method in which it Call by Reference is a method in which it
passes the copies of actual parameters to passes the reference or address of the
the formal parameters inside the function. actual parameter to the function's formal
And as you know, it passes the copies, so parameters, which means if there is any
even if there is any change in the values change in the values inside the function, it
inside the function, it will not reflect that reflects that change in the actual values.
change in the actual values.
Click here
For Videos

“Functions are independent program modules that are designed to carry out a particular task.”

In functions we have two types:

 Built-in (Library) functions


 User-defined functions

There are the following advantages of C functions.


•By using functions, we can avoid rewriting same logic/code again and again in a program.
•We can call C functions any number of times in a program and from any place in a program.
•We can track a large C program easily when it is divided into multiple functions.
•Reusability is the main achievement of C functions.
•However, Function calling is always a overhead in a C program.
Click here
For Videos

Actual parameters Formal parameters


When a function is called, the values that
The values which are received by the function,
are passed in the call are called actual
and are assigned to formal parameters.
parameters.

They are also called as argument list. They are also called as dummy parameters.

The variables used in the function call is The variables defined in function header are
called actual parameters. called formal parameters.

These are used in calling function when a These are used in function header of the called
function is called or invoke. function.
Actual parameters sends data to the formal Formal parameters receives data from actual
parameters. parameters.
Click here
For Videos

https://www.youtube.com/watch?v=E2fW4NQMZqI
Click here
For Videos

#include <stdio.h>
struct student
{
char name[30];
int rollNo;
struct DOB
{
int dd;
int mm;
int yy;
}DOB;/*created structure variable DOB*/
};
int main(){
struct student std;
printf("Enter name: ");
scanf("%C",&std.name);
printf("Enter roll number: ");
scanf("%d",&std.rollNo);
printf("Enter Date of Birth [DD MM YY] format: ");
scanf("%d%d%d",&std.DOB.dd,&std.DOB.mm,&std.DOB.yy);
printf("\nName : %s \nRollNo : %d \nDate of birth : %02d/%02d/%02d\n",std.name,std.rollNo,std.DOB.dd,std.DOB.mm,std.DOB.yy);
return 0;
}
Click here
For Videos
Click here
For Videos

Example of Structure Example of Union

struct student union Student {


{ char name[32];
int rollno; int age;
char name[50]; string email;
string phone; };
};
Click here
For Videos
“A pointer is a variable that holds the address of another variable. The pointer variable contains only the address of the
referenced variable, not the value stored at that address.“

Pointer arithmetic is very important to understand if you want to have complete knowledge of pointer. In this topic, we will study
how the memory addresses change when you increment a
pointer.

In a 16 bit machine, the size of all types of the pointer, be it int, float, char*, or double* is always 2 bytes. But when we
perform any arithmetic function like increment on a pointer, changes occur as
per the size of their primitive data type.

int*i;
i++
In the above case, the pointer will be 2 bytes. And when we increment it, it will increment by 2 bytes because int is
also of 2 bytes.

float*i;
i++;
In this case, the size of a pointer is still 2 bytes. But now, when we increment it, it will increment by 4 bytes because
the float is 4 bytes.
Click here
For Videos
THANK YOU

EXPLORE ELECTRONICS
Click For Videos: https://www.youtube.com/c/ExploreElectronics
All The Best For Exams….

https://www.youtube.com/c/ExploreElectronics

You might also like