Computer Programming University Question Answer
Computer Programming University Question Answer
1. List some important hardware and software technologies of fifth generation computers.
Super Large Scale Integrated Chips(SLSI)
Parallel Technologies
Dual Core Processor
Artificial Intelligence, Natural Language Processing.
2. Write two characteristics of pseudocode.
Composed of a sequence of statements or steps
Statements are often numbered sequentially.
Statements are written in simple English
Each statement is written on a separate line
Keywords and indentation are used to signify control structures or blocks of repetition
There is no fixed syntax.
Clarity of expression is essence of pseudocode.
3. What are various types of C operators.
Arithmetic Operator
Relational Operator
Logical Operator
Bitwise Operator
Assignment Operator
4. Write a for loop statement to print numbers from 10 to 1.
for(count = 10; count >0; count--)
printf("%d ", count);
5. Define array
Array is a datastructure that is used for storage of homogeneous data , i.e. the data of same type.
6. Name any two library functions used for string handling functions.
strlen
strcmp
strcpy
strrev
strcat
strstr
7. What is the need for functions?
8.
Union
PART-B
11.a)write in detail about the evolution and the various generations of computer. (16).
Evolution of computers
ABACUS:
NAPIER BONES and SLIDE RULE:
PASCALINE-1642:
STEPPED RECKONER-1694:
DIFFERENCE ENGINE-1822:
1889: ->Jacquared loom concept to computing.
1944: ->Invention of Mark-I, built in partnership between Harvard Aiken and IBM.
1946: ->developed ENIAC-Electronic Numerical Integrator and Calculator.
1949: ->EDSAC-Electronic Delay Storage Automatic Calculator.
1951: ->UNIVAC- Universal Automatic Computer.
1960->LARC was invented.
1970: ->Invention of microprocessors, processors on IC chip.
Output->monitor
Interface->Operating system
This allowed the device to run many different applications at one time.
Ex: NCR 395, B6500
Characteristics:
Registers
Input Unit
Output Unit
Control
Unit
Arithmetic /
logic Unit
Data flow
Instruction flow
Input Devices:
Input devices -electro mechanical devices - feed information into the computer for analysis, storage and
to give commands to the central processing unit (CPU).
Computer can accept input in two ways.
-> Manual Ex. Keyboard and Mouse.
-> Direct - fed into the computer automatically from a source document
Input device are, KeyboardMouseJoystickScanners.
Central Processing Unit:
The central processing unit -brain of a computer. - converts data into meaningful information.controls all internal and external devices,- - controls the usage of main memory to store data and
instruction ,and control the sequence of operations
three main subsystems,
Arithmetic/logic unit (ALU) --Control Unit (CU)--Registers.
Arithmetic/logic unit (ALU)
-executes all the arithmetic and logical operations on the data.
-contains two units, Arithmetic unit - Logic Unit
Arithmetic Unit
-performs actual computing - arithmetic calculation
Logic Unit:
- perform logical operations based on the instructions provide it.
- Logical operations of logic unit can test for three conditions.
->equal to condition -> Less than condition -> Greater than condition
Control Unit:
- checks the correctness of sequence of operations.-- controls the input/output devices - directs the overall
functioning of the other units of the computer.
Registers:
- special purpose, high speed temporary memory units -- hold various types of information such as data,
instructions, addresses, and the intermediate results of calculation.-- holds the information that the CPU is
currently working on.
Output devices:
Computer communicate with human beings using output devices.
The physical form of output is known as hard copy.
The electronic version of an output- known as soft copy.
Output devices: Monitor.-Printer.-Plotters.-Audio response.
Memory:
Computer requires memory to process data and store output. Memory refers to the electronic holding
place for instruction and data.
Classify the memory into two categories,
Primary memory-> to handle the data- known as main memory, store data and instructions for processingclassified into Random Access Memory (RAM) and Read Only Memory (ROM).
Secondary memory-> to store the output. - known as auxiliary memory or external memory - for storing
instruction and data - data stored are permanent in nature - larger storage capacity than primary memory.
12.a) write about the need and types of looping statements in c language and discuss with examples(16).
NEED:
do the same thing many times.
There are three basic types of loops which are:
for loop
syntax with program.
while loop
syntax with program.
do while loop
syntax with program.
12.b) write about the need and types of branching statements in c language and discuss with examples
(16).
Many times it is required to alter the flow of sequence of instructions.
Branching Statement are of following categories:
1. If Statement
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("\nEnter the Second matrix->");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&b[i][j]);
printf("\nThe First matrix is\n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",a[i][j]);
}
printf("\nThe Second matrix is\n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",b[i][j]);
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
printf("\nThe Addition of two matrix is\n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",c[i][j]);
}
return 0;
}
14. a) i) Function Declaration. (8).
A function in C can perform a particular task, and supports the concept of modular programming design
techniques.
Function Declaration
returntype function-name(Parameters);
Example:
int square(int, int);
Program example:
#include<stdio.h>
#include<conio.h> void main()
{
int n; long int i;
long int fibo(int n); clrscr();
printf("Enter the limit:\n");
scanf("%d",&n);
i=fibo(n);
printf("\nThe %dth Fibonacci number is %ld",n,i); getch();
}
long int fibo(int n)
{
int old_no,currnt_no,sum,i; i=1;
old_no=0; currnt_no=1; while(i<=n)
{
sum=old_no+currnt_no; old_no=currnt_no; currnt_no=sum;
i++;
printf("\n%d",sum);
}
return(sum);
}
ii) Call by reference, call by value: (8)
(i) CALL BY VALUE:
When the value is passed directly to the function it is called call by value. In call by value only a copy of the
variable is only passed so any changes made to the variable does not reflects in the calling function.
Example:
#include<stdio.h>
#include<conio.h>
swap(int,int); void main()
{
int x,y;
printf("Enter two nos"); scanf("%d %d",&x,&y);
printf("\nBefore swapping : x=%d y=%d",x,y);
swap(x,y);
getch();
}
swap(int a,int b)
{
int t;
t=a;
a=b;
b=t;
printf("\nAfter swapping :x=%d y=%d",a,b);
}
(ii)Call by Reference:
#include <stdio.h>
#include <conio.h>
void swap(int*,int*);
int main()
{
int x,y;
printf("Enter the value of x and y \n"); scanf("%d%d",&x,&y);
printf("Before swapping\nx = %d\ny = %d\n",x,y);
swap(&x,&y);
printf("After swapping\nx = %d\ny = %d",x,y); getch();
return 0;
}
void swap (int *a, int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
14. b) i) Function with and without arguments with example for each: (10)
Explain any one of the given below:
Function with argument with return type:
struct student {
char name [50];
int roll;
char address[50];
struct date dob;
};
main()
{
int i,j,n;
struct student a[50];
{
printf("How many data you want to input?");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter your name ");
scanf("%s",&a[i].name);
printf("Enter your roll");
scanf("%d",&a[i].roll);
printf("Enter your address ");
scanf("%s",&a[i].address);
printf("Enter your Date of Birth (dd/mm/yy)");
scanf("%d%d%d",&a[i].dob.day,&a[i].dob.month,&a[i].dob.year);
}
printf("\n");
for(j=0;j<n;j++)
{
printf("Name :- %s \n ",a[j].name);
printf("Roll Number :- %d\n",a[j].roll);
printf("Address :- %s \n ",a[j].address);
printf("Date of Birth(dd/mm/yy) :- %d/%d/%d\n",a[j].dob.day,a[j].dob.month,a[j].dob.year );
printf("\n");
}
}
}
15. b) C program to create mark sheet for students using structure: (16)
#include
#include
struct marks
{
char n[10];
int m[5];
float avg[3];
int tot[3];
};
struct marks stu[3];
void main()
{
int i,j,n;
printf("Enter the number of students\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the name of the students-%d\n",i+1);
scanf("%s",stu[i].n);
stu[i].tot[i]=0;
for(j=0;j<5;j++)
{
printf("Enter the marks%d\n",j+1);
scanf("%d",&stu[i].m[j]);
stu[i].tot[i]+=stu[i].m[j]);
}
stu[i].avg[i]=(float)(stu[i].tot[i]/5);
}
printf("NAME\tMARK1\tMARK2\tMARK3\tMARK4\tMARK5\tTOTAL\tAVERAGE\tRESULT\tCLASS\n")
;
for(i=0;i<n;i++)
{
printf("%s\t%d\t%d\t%d\t%d\t%d\t%d\t%5.2f",stu[i].n,stu[i].m[0],stu[i].m[1],stu[i].m[2],stu[i].m[3],
stu[i].m[4],stu[i].tot[i],stu[i].avg[i]);
if(stu[i].m[0]>34&&stu[i].m[1]>34&&stu[i].m[2]>34&&stu[i].m[3]>34 && stu[i].m[4]>34)
{
printf("\tPass");
if(stu[i].avg[i]>59)
printf("\tFirst");
if(stu[i].avg[i]<60&&stu[i].avg[i]>50)
printf("\tSecond\n");
if(stu[i].avg[i]<50)
printf("\tThird\n");
}
else
printf("Fail");
}
getch();
}