Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

CHAPTER 1 :- FUNDAMENTALS OF COMPUTER

COMPUTER :
A computer is a machine or device that performs processes, calculations and operations based on
instructions provided by a software or hardware program. It has the ability to accept data (input), process it,
and then produce outputs.

COMPUTER AS A SYSTEM
1 Hardware :
The hardware is the machinery itself. It is made up of the physical parts or devices of the computer system
like the electronic Integrated Circuits (ICs), magnetic storage media and other mechanical devices like input
devices, output devices etc. All these various hardware are linked together to form an effective functional
unit.
Example: keyboard , motherboard, drive, ram, network card etc…

1) Input devices : Input devices are the dev ices which are used to feed programs and data to the
computer. A computer can accept data only in a specific form. Therefore these input devices
transform the data fed to them, into a form which can be accepted by the computer.
Example : keyboard, floppy disks, mouse, microphone etc…

2) Output devices : The output devices give the results of the process and computations to the
outside world. The output units accept the results produced by the computer, convert them into a
human readable form and supply them to the users.
Example : printers, plotters, display screens…

3) Central processing unit (CPU) : This is the brain of any computer system. CPU is made of
three parts:
a) The control unit : The Control Unit controls the operations of the entire computer system.
The control unit gets the instructions from the programs stored in primary storage unit
interprets these instruction an subsequently directs the other units to execute the instructions.
b) The arithmetic logic unit : The Arithmetic Logic Unit (ALU) actually executes the
instructions and performs all the calculations and decisions. results are sent to the output
storage section and the output devices.
c) The primary storage unit : This is also called as Main Memory. Stores data and programs
during actual processing. Stores temporary results of intermediate processing. Stores results of
execution temporarily.
Types of memory
1) Primary memory(main memory) : Primary memory holds only those data and instructions on which the
computer is currently working. It has a limited capacity and data is lost when power is switched off. It is
mainly divided into two RAM and ROM.

2) Secondary memory : This type of memory is also known as external memory or non-volatile. It is
slower than the main memory. These are used for storing data/information permanently.
Example : Disk, CD-ROM, DVD, etc…

3) Cache memory : Cache memory is a very high speed semiconductor memory which can speed up the
CPU. It is used to hold those parts of data and program which are most frequently used by the CPU.

2 Software :
Computer software, or just software, is a collection of computer programs and related data that provides the
instructions for telling a computer what to do and how to do it. Any set of instructions that guides the
hardware and tells it how to accomplish each task
.

1) System software : System software is computer software designed to operate the computer
hardware to provide basic functionality and to provide a platform for running application software.

• Operating system : An operating system is a program that controls the execution of application
programs and acts as an interface between the user of a computer and the computer hardware. It performs all
the basic tasks like file management, memory management, process management, handling input and output,
and controlling peripheral devices such as disk drives and printers. Most common operating systems are
Microsoft Windows, Linux etc..

• Device driver : A device driver is software that contains a set of instructions that command a
computer’s operating system on how to communicate with the hardware so that it can function properly.

• Utility programmes : A program that performs a specific task related to the management of
computer functions, resources, or files, as password protection, memory management, virus protection, and file
compression.

2) Application software : Application software is a type of computer program that performs a


specific personal, educational, and business function. Each programme is designed to assist the user
with a particular process , which may be related to productivity, creativity, and/or communication.

Example
• Microsoft suite of products (Office, Excel, Word, PowerPoint, Outlook, etc.)

• Internet browsers like Firefox, Safari, and Chrome.


3 Data:
Data is essentially the raw facts and figures that we input in the computer. The data gets processed via the
computer system and becomes information, which is processed and organized data. Information can then be
used for decision-making purposes.

4 User :
A person who uses computers for work or entertainment or communication or business

⁕⁕⁕⁕⁕⁕⁕
C PROGRAMMING
1. Wap to print simple message.

INPUT:

#include <stdio.h>
int main()
{
printf("FUNDAMENTALS OF PROGRAMMING LANGUAGES");
return 0;
}

OUTPUT:
2. Wap to calculate average of 5 numbers.

INPUT:

#include<stdio.h>
using namespace std;
int main()
{
Int a,b,c,d,f,n=5,m;
printf("enter the value of a:");
scanf("%d",&a);
printf("enter the value of b:");
scanf("%d",&b);
printf("enter the value of c:");
scanf("%d",&c);
printf("enter the value of d:");
scanf("%d",&d);
printf("enter the value of f:");
scanf("%d",&f);
m=(a+b+c+d+f)/n;
printf("average is:");
printf("%d",m);
return 0;
}

OUTPUT:
3. Wap to multiply three numbers

INPUT:

#include<stdio.h>
using namespace std;
int main()
{
int a,b,c;
printf("enter the value of a:");
scanf("%d",&a);
printf("enter the value of b:");
scanf("%d",&b);
printf("enter the value of c:");
scanf("%d",&c);
int p=a*b*c;
printf("product is:%d",p);
return 0;
}

OUTPUT:
4. Wap to print area of a circle.

INPUT:

#include<stdio.h>
int main()
{
int r=2;
int π=3.14;
int area=2*π*r;
printf("value of the area is : %d",area);
return 0;
}

OUTPUT:
5. Wap to check given number is even or odd.

INPUT:

#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);

// true if num is perfectly divisible by 2


if(num % 2 == 0)
printf("%d is even.", num);
else
printf("%d is odd.", num);

return 0;
}

OUTPUT:
6. Wap to check given year is leap year or not?

INPUT:

#include<stdio.h>
using namespace std;
int main() {
int year = 1999;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
printf(" is a leap year");
else
printf("%d is not a leap year",year);
return 0;
}

OUTPUT:
7. Wap to print the name of day according to user Choice using switch.

INPUT:

#include <stdio.h>

using namespace std;

int main()
{
int weeknumber;

printf("Enter week number(1-7): ");


scanf("%d",&weeknumber);
switch(weeknumber)
{
case 1: printf("Monday");
break;
case 2: printf("Tuesday");
break;
case 3: printf("Wednesday");
break;
case 4: printf("Thursday");
break;
case 5: printf("Friday");
break;
case 6: printf("Saturday");
break;
case 7: printf("Sunday");
break;
default: printf("Invalid input! Please enter week no. between 1-7.");
}

return 0;

}
OUTPUT:
8. Wap to print 1 to 10 no by while loop.

INPUT:

#include <stdio.h>
int main() {
int input = 1;
while (input <= 10) {
printf("\n%d",input);
input++;
}
}

OUTPUT:
9. Wap to print 1 to 10 Numbers by using do while.

INPUT:

#include <stdio.h>
using namespace std;
int main() {
int i = 1;
do{
printf("\n%d",i);
i++;
} while (i <= 10) ;
}

OUTPUT:
10. Wap to print 1 to 10 by using for loop.

INPUT:

#include <stdio.h>

using namespace std;

int main() {
for (int i = 1; i <= 10; ++i)
{
printf("\n%d",i);
}
return 0;
}

OUTPUT:
11. Wap to calculate factorial of a given number using for loop.

INPUT:

#include <stdio.h>
using namespace std;
int main() {
int n, fact = 1, i;
printf("Enter a number:\n");
scanf("%d", &n);
printf("%d\!\=",n);
for(i=1; i<=n; i++)
fact = fact * i;
printf("%d",fact);

return 0;
}

OUTPUT:
12. Wap to print the fibonacci series.

INPUT:

#include<stdio.h>
using namespace std;
int fib(int n) {
if (n <= 1)
return n;
return fib(n-1) + fib(n-2);
}
int main () {
int n = 10, i;
for(i=0;i<n;i++)
printf("%d\,",fib(i));
return 0;
}

OUTPUT:
13. Wap to print reverse of a number using for loop.

INPUT:

#include <stdio.h>
using namespace std;

int main()
{
int num, r, sum = 0, t;
printf("\n\n Display the number in reverse order:\n");
printf("\n");
printf(" Input a number: ");
scanf("%d",&num);
for (t = num; num != 0; num = num / 10)
{
r = num % 10;
sum = sum * 10 + r;
}
printf(" The number in reverse order is : ");
printf("%d",sum);
}

OUTPUT:
14. Wap to print odd numbers between 1 to 50.

INPUT:

#include<stdio.h>
using namespace std;

int main()
{
int number=50;

printf("\nList of Odd Numbers from 1 to ");


printf("%d are\n",number);
for(int i = 1; i <= number; i++)
{
if ( i % 2 != 0 )
{
printf("%d\,",i);
}
}

return 0;
}

OUTPUT:
15. Wap to add two numbers using Functions.

INPUT:

#include <stdio.h>
using namespace std;

int main()
{
int FirstNumber, SecondNumber, SumOfTwoNumbers;

printf("Enter two integers:\n ");


scanf("%d%d",&FirstNumber,&SecondNumber);

SumOfTwoNumbers = FirstNumber + SecondNumber;

printf("%d\+%d\=%d",FirstNumber,SecondNumber,SumOfTwoNumbers);

return 0;
}

OUTPUT:
16. Wap to show concept of function no argument and with return.

INPUT:

#include <stdio.h>
int my_function() {
return 50;
}
int main() {
int x;
x = my_function();
printf("Returned Value: %d", x);
}

OUTPUT:
17. Wap to show the concept of function with argument and no return.

INPUT:

#include <stdio.h>
void my_function(int x) {
}
int main() {
int x;
x = 10;
my_function(x);
}

OUTPUT:
18. Wap to swap two numbers using call by value.

INPUT:

#include <stdio.h>

void swap(int, int);

int main()
{
int x=30, y=9;

printf("Before Swapping\nx = %d\ny = %d\n", x, y);


swap(x,y);
return 0;
}

void swap(int a, int b)


{
int temp;

temp = b;
b = a;
a = temp;
printf("Values of a and b is %d %d\n",a,b);
}

OUTPUT:
19. Wap to swap two no by call by reference.

INPUT:

#include <stdio.h>

void swap(int*, int*);

int main()
{
int x=15, y=3;

printf("Before Swapping\nx = %d\ny = %d\n", x, y);

swap(&x, &y);

printf("After Swapping\nx = %d\ny = %d\n", x, y);

return 0;
}

void swap(int *a, int *b)


{
int temp;

temp = *b;
*b = *a;
*a = temp;
}

OUTPUT:
20. Wap to print input elements using One-D array.

INPUT:

#include<stdio.h>

int main()
{
int arr[5], i;

for(i = 0; i < 5; i++)


{
printf("Enter a[%d]: ", i);
scanf("%d", &arr[i]);
}

printf("\nPrinting elements of the array: \n\n");

for(i = 0; i < 5; i++)


{
printf("%d ", arr[i]);
}
return 0;
}

OUTPUT:
21. Wap to find the maximum value from array.

INPUT:

#include <stdio.h>
int main() {
int n;
double arr[100];
printf("Enter the number of elements ");
scanf("%d", &n);

for (int i = 0; i < n; ++i) {


printf("Enter number%d: ", i + 1);
scanf("%lf", &arr[i]);
}

for (int i = 1; i < n; ++i) {


if (arr[0] < arr[i]) {
arr[0] = arr[i];
}
}

printf("Largest element = %.2lf", arr[0]);

return 0;
}

OUTPUT:
22. Wap to print the sum of all array elements.

INPUT:

#include <stdio.h>

int main() {
int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
int sum, loop;

sum = 0;

for(loop = 9; loop >= 0; loop--) {


sum = sum + array[loop];
}

printf("Sum of array is %d.", sum);

return 0;
}

OUTPUT:
23. Wap to print input elements using Two-D array.

INPUT:

#include <stdio.h>
int main()
{
int b[2][3];
int i,j,num;
printf("Enter elements into 2-D array: ");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
scanf("%d" , &b[i][j]);
}
}
b[0][2]=10;
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
printf("\t%d" , b[i][j]);
}
printf("\n");
}
return 0;
}

OUTPUT:
24. Wap to add, subtract and multiply two matrices.

a) To add two matrices

INPUT:

#include <stdio.h>
int main() {
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
printf("Enter the number of rows (between 1 and 100): ");
scanf("%d", &r);
printf("Enter the number of columns (between 1 and 100): ");
scanf("%d", &c);

printf("\nEnter elements of 1st matrix:\n");


for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
printf("Enter element a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]);
}

printf("Enter elements of 2nd matrix:\n");


for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
printf("Enter element b%d%d: ", i + 1, j + 1);
scanf("%d", &b[i][j]);
}

// adding two matrices


for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
sum[i][j] = a[i][j] + b[i][j];
}
// printing the result
printf("\nSum of two matrices: \n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
printf("%d ", sum[i][j]);
if (j == c - 1) {
printf("\n\n");
}
}

return 0;
}

OUTPUT:
b) To multiply two matrices

INPUT:
#include <stdio.h>
int main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];

printf("Enter number of rows and columns of first matrix\n");


scanf("%d%d", &m, &n);
printf("Enter elements of first matrix\n");

for (c = 0; c < m; c++)


for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);

printf("Enter number of rows and columns of second matrix\n");


scanf("%d%d", &p, &q);

if (n != p)
printf("The multiplication isn't possible.\n");
else
{
printf("Enter elements of second matrix\n");

for (c = 0; c < p; c++)


for (d = 0; d < q; d++)
scanf("%d", &second[c][d]);

for (c = 0; c < m; c++) {


for (d = 0; d < q; d++) {
for (k = 0; k < p; k++) {
sum = sum + first[c][k]*second[k][d];
}

multiply[c][d] = sum;
sum = 0;
}
}

printf("Product of the matrices:\n");

for (c = 0; c < m; c++) {


for (d = 0; d < q; d++)
printf("%d\t", multiply[c][d]);

printf("\n");
}
}

return 0;
}

OUTPUT:
c) To subtract two matrices

INPUT:

#include <stdio.h>
int main()
{
int m, n, c, d, first[10][10], second[10][10], difference[10][10];

printf("Enter the number of rows and columns of matrix\n");


scanf("%d%d", &m, &n);
printf("Enter the elements of first matrix\n");

for (c = 0; c < m; c++)


for (d = 0 ; d < n; d++)
scanf("%d", &first[c][d]);

printf("Enter the elements of second matrix\n");

for (c = 0; c < m; c++)


for (d = 0; d < n; d++)
scanf("%d", &second[c][d]);

printf("Difference of entered matrices:-\n");

for (c = 0; c < m; c++) {


for (d = 0; d < n; d++) {
difference[c][d] = first[c][d] - second[c][d];
printf("%d\t",difference[c][d]);
}
printf("\n");
}

return 0;
}
OUTPUT:
25. Wap to print sum of diagonal elements of a matrix.

INPUT:

#include<stdio.h>
int main()
{
int i, j, rows, columns, a[10][10], Sum = 0;
printf("\n Please Enter Number of rows and columns : ");
scanf("%d %d", &i, &j);
printf("\n Please Enter the Matrix Elements \n");
for(rows = 0; rows < i; rows++)
{
for(columns = 0;columns < j;columns++)
{
scanf("%d", &a[rows][columns]);
}
}
for(rows = 0; rows < i; rows++)
{
Sum = Sum + a[rows][rows];
}
printf("\n The Sum of Diagonal Elements of a Matrix = %d", Sum );
return 0;}
OUTPUT:
26. Wap to print record of a school student using structure.

INPUT :

#include<stdio.h>
struct student
{
char name[50],cls[5];
int r;
float mrk;
}
s[100];
int main()
{
int i;
printf("record of students\n\n");
for(i=1;i<4;i++)
{
s[i].r=i;
printf("\nROLL NO\t:%d\n",s[i].r);
printf("NAME\t:");
scanf("%s",s[i].name);
printf("CLASS\t:");
scanf("%s",s[i].cls);
printf("MARK\t:");
scanf("%f",&s[i].mrk);
}
return 0;
}
OUTPUT :
27. Wap to print record of a school student using union.

INPUT :

#include <stdio.h>
union student
{
char name[52],cls[5];
float mrk;
int r;
} u[100];
int main()
{
union student a1;
int i;
printf("Record of students\n");
for(i=1;i<4;++i)
{
a1.r=i;
printf("\n\nROLL NO\t:%d",a1.r);
printf("\nNAME\t:");
scanf("%s",a1.name);
printf("CLASS\t:");
scanf("%s",a1.cls);
printf("\MARK\t:");
scanf("%f",&a1.mrk);
}
return 0;
}
OUTPUT :
28. Wap to print address & value of variable and address of pointer
variable.

INPUT :
#include<stdio.h>
int main()
{
int *p;
int i=3;
p=&i;
printf("value of variable 'i'is\t\t:%d",*p);
printf("\nadress of variable 'i' is\t:%d",p);
printf("\nadress of pointer 'p' is\t:%d",&p);
return 0;
}

OUTPUT :
29. Wap to show the concept of pointer to pointer.

INPUT :

#include<stdio.h>
int main()
{
int i=300,*p,**ptr;
p=&i;
ptr=&p;
printf("value of variable 'i' in 3 ways are:\n%d %d %d",i,*p,**ptr);
printf("\nadress of variable 'i' is:\n%d",p);
printf("\nadress of pointer 'p' is:\n%d",ptr);
return 0;
}

OUTPUT :
30. Wap to show use of auto, external and static variable.

INPUT :

#include <stdio.h>
int x;
void autoStorageClass()
{
printf("\nDemonstrating auto class\n\n");
auto int a = 32;
printf("Value of the variable 'a'declared as auto: %d\n",a);
printf("\n\n");
}
void externStorageClass()
{
printf("\nDemonstrating extern class\n\n");
extern int x;
printf("Value of the variable 'x'declared as extern: %d\n",x);
x = 2;
printf("Modified value of the variable 'x' declared as extern: %d\n", x);
printf("\n\n");
}
void staticStorageClass()
{
int i = 0;
printf("\nDemonstrating static class\n\n");
printf("Declaring 'y' as static inside the loop.\nBut this declaration will occur only once as 'y' is
static.\nIf not, then every time the value of 'y' will be the declared value 5 as in the case of variable
'p'\n");
printf("\nLoop started:\n");
for (i = 1; i < 5; i++) {
static int y = 5;
int p = 10;
y++;
p++;
printf("\nThe value of 'y',declared as static, in %d iteration is %d\n",i, y);
printf("The value of non-static variable 'p', in %d iteration is %d\n",i, p);
}
printf("\nLoop ended:\n");
printf("\n\n");
}
int main()
{
printf("A program to demonstrate Storage Classes in C\n\n");
autoStorageClass();
externStorageClass();
staticStorageClass();
printf("\n\nStorage Classes demonstrated");
return 0;
}

OUTPUT :
31. Wap to enter a mixed data into a file.

INPUT :
#include<stdio.h>
int main()
{
int r=4;
FILE *fp;
fp=fopen("D://term/data.txt","w");
fprintf(fp,"ANU\nROLL NO:20\nTOTAL MARK:560\nRANK:%d",r);
fclose(fp);
return 0;
}

OUTPUT :
32. Wap to read a mixed data from a file.

INPUT :

#include <stdio.h>
int main()
{
FILE * fp;
char c;
fp = fopen("D://term/data.txt", "r");
while ((c = getc(fp)) != EOF) printf("%c", c);
fclose(fp);
return 0;
}

OUTPUT :

END
************

You might also like