August 2010 Bachelor of Science in Information Technology (BScIT) – Semester 1/ Diploma in Information Technology (DIT) – Semester 1 BT0065 – C Programming and Data Structures – 3 Credits (Book ID: B0949) Assignment Set – 1 (60 Marks) Answer all questions 10 x 6 = 60 1. What do you mean by data types? Explain. Answe:- Data type is essential when we define a variable. Because when variable is defined we must maintain the data type along with the variable so that it possible to allocate the memory space. et us consider the analogous example of cooking. At the time of defined a container we must define its capacity. If it is large enough, then space is wasted and if is small than data can be overflowed. In C language, there are four Data Type. a) Primary or fundamental data type b) User defined data type c) Derived data type d) Empty data type 2. Write an algorithm to print all even numbers in descending order and draw the flowchart. Answer:- Flowchart to print all even numbers in descending order from 100 till 2.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
August 2010
Bachelor of Science in Information Technology (BScIT) – Semester 1/
Diploma in Information Technology (DIT) – Semester 1
BT0065 – C Programming and Data Structures – 3 Credits
(Book ID: B0949)
Assignment Set – 1 (60 Marks)
Answer all questions 10 x 6 = 60
1. What do you mean by data types? Explain.
Answe:- Data type is essential when we define a variable. Because when variable is defined
we must maintain the data type along with the variable so that it possible to allocate the
memory space. et us consider the analogous example of cooking. At the time of defined a
container we must define its capacity. If it is large enough, then space is wasted and if is small
than data can be overflowed.
In C language, there are four Data Type.
a) Primary or fundamental data type
b) User defined data type
c) Derived data type
d) Empty data type
2. Write an algorithm to print all even numbers in descending order and draw the flowchart.
Answer:- Flowchart to print all even numbers in descending order from 100 till 2.
3. Write a C program to add all numbers between 100 and 200 that contain the digit 5.
Answer:-
#include <stdio.h>
#include <conio.h>
main(void)
{
int t=0,a=101,b=0,c=100;
for(;a<=200;a++)
{
b=a-c;
if(b%10==5||b/10==5)
t+=a;
}
printf("\nSum of the numbers is %d",t);
printf("\n\n\t\t\tWritten for smu\n\n");
getch();
}
4. Write a program that accepts 15 different numbers and find the LCM and HCM.
Answer:-
#include <stdio.h>
#include <conio.h>
int hcmz(int,int);
int lcmz(int,int);
main(void)
{
int num[14],c=15,v,max,min;
printf("Enter 15 numbers:\n");
for(v=0;v<c;v++)
scanf("%d",&num[v]);
min=num[0];
for(v=1;v<c;v++)
min=hcmz(min,num[v]);
printf("\nHCM is %d",min);
max=num[0];
for(v=1;v<c;v++)
max=lcmz(max,num[v]);
printf("\nLCM is %d",max);
printf("\n\n\t\t\tWritten for smu.covertbay.com\n\n");
getch();
}
int lcmz(int e,int f)
{
int lcm;
lcm = e*f/hcmz(e,f);
return lcm;
}
int hcmz(int e,int f)
{
int dump,rem;
if(e<f)
{
dump=e;
e=f;
f=dump;
}
while(1)
{
rem=e%f;
if(rem==0)
return f;
else
e=f;
f=rem;
}
}
5. Distinguish library functions and user defined functions.
Answer:- Unit 5 (Library function = predefined function | user defined function = defined
by user)
6. Write a program to illustrate the usage of pointers with arrays and functions.
Answer:-
#include <stdio.h>
#define ROWS 3
#define COLS 4
void print(int rows, int cols, int *matrix);
int main(int argc, char *argv[]) {
int a[ROWS*COLS], i;
/* initialize */
for (i = 0; i < ROWS*COLS; i++) {
a[i] = i+1;
}
/* display */
print(ROWS,COLS,a);
return 0;
}
void print(int rows, int cols, int *matrix) {
int i, j, *p = matrix;
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
printf("%3d",*(p + (i * cols) + j)));
}
puts("");
}
}
7. Write a program that reads numbers from a file and find the largest and smallest among
them.
Answer:-
#include<stdio.h>
#include<lib.h>
void main(void)
{
FILE *fp;
int i;
clrscr();
while(!eof(fp))
{
a[i]=fgetc(fp);
i++
getch();
}
8. What do you mean by Abstract Data Type?
Answer:- an abstract data type is a mathematical model for a certain class of data structures
that have similar behavior; or for certain data types of one or more programming languages
that have similar semantics. An abstract data type is defined indirectly, only by the operations
that may be performed on it and by mathematical constraints on the effects (and possibly cost)
of those operations.
For example, an abstract stack data structure could be defined by two operations: push, that
inserts some data item into the structure, and pop, that extracts an item from it; with the
constraint that each pop always returns the most recently pushed item that has not been
popped yet. When analyzing the efficiency of algorithms that use stacks, one may also specify
that both operations take the same time no matter how many items have been pushed into the
stack, and that the stack uses a constant amount of storage for each element.