Sie sind auf Seite 1von 3

CSE-101 3rd ASSIGNMENT 2010

Foundation of computting

Submitted to: Mr. Balijepali Sivakiran


Submitted by: Mukesh chettri
Roll number: RE1001A25
Section: E1001

Ques 1 :- Write a program to count negative elements from the list using arrays.
Ans:- #include<stdio.h>
#include<conio.h>
void main()
{ int a[100],n,c=0;
clrscr();
printf("\n\nENTER ARRAY SIZE:");
scanf("%d",&n);
printf("\n\nENTER ARRAY ELEMENTS:");
for(int i=0;i<n;i++)
{ scanf("%d",&a[i]);
if(a[i]<o)
c++;
}
printf("\n\n TOTAL NEGATIVE ELEMENTS ARE:%d",c);
getch();
}
Ques 2: - How can you differentiate a lower level array from the higher level array?
Ans: -A lower level array may be refferred to as a single dimensional array whereas a high level array is
multidimensional array. Generally 2 dimensional array is seen usually but it may be 3 or more than 3
dimensional.Handeling or dealing with low level array is easier than high level array.low level array contains
1braces and high level array contains more than 1 braces.we can simply differentiate a lower level array from
the higher level array by looking their initialization and declaration.
For example:
A single dimensional array i.e low level arrays
int[18];
stored in the memory as a[0]=1;
a[1]=2; etc.
And multi dimensional array i.e, high level array
int[5][2][6];
stored in the memory as a[0][1]=2; etc;

Ques 4:- How will you initialize a three dimensional array thread [3] [2] [3]? How will
you refer the first and last element in this array?
Ans:- Initialisation of array
int a [2][2][3]; //declaration
a[2][2][3]={
{1,2,3},{4,5,6}},
{{7,8,9},{10,1}}
}
}; //initialization
1st element referred as: a[0][0][0];
Last element referred as: a[1][1][2];

Q5 Can an array of pointer to strings be used to collect strings from the keyboard? If not, why
not? How, if yes?
Ans:-Yes an array of pointer to string be used to collect strings from the keyboard. As array of pointer to a
string points to an string. Pointer arrays offer a particularly convenient method for storing strings. In this
situation, each array element is a character-type pointer that indicates the beginning of a separate string. Thus ,
an n-element array can point to n different strings. Each individual string can be accessed by referring to its
corresponding pointer Suppose we want to enter following string:-
PACIFIC
ATLANTIC
BERING
CASPIAN
Using array of pointers it can be done as follows:-
Char *names[10];
Thus names[0] will point to PACIFIC, names[1] will point to ATLANTIC, and so on. Note that it is not
necessary to include a maximum string size within array declaration. However, a specified amount of memory
will have to be allocated for each string later in the program, e.g.,
names[i]=(char *) malloc(12 * sizeof(char)); Thus , an array of pointer can be used to collect strings from the
keyboard:
char *ptr[5];
//reading input strings.
do
{ ptr[n]=(char*) malloc(5*sizeof(char));
//allocating dynamic memory .
scanf(%s”,ptr[n]);
}
while(strcmp(ptr(n++),”END”))
Ques 6 :- Give an example of a structure declaration without a use of tag? What are its
advantages and disadvantages?
Ans:- Structure declaration without the use of tag:
struct
{ int eage;
char enam[80];
}e1,e2;
Which is equivalent to
struct employe
{ int eage;
char enam[80];
}e1,e2;

Advantage Disadvantage
1. The structure variable, declared 1. Any future declaration is not possible
without the use of tag are global in as tag is missing and it can’t be used
nature ,if the structure body occurs to create /declare new structure
outside all functions and before variable anywhere else in the program.
void main(). The structure variables declared allat
once, along with structure ,body only
exist.

Q7 .Create a structure to specify data on students given below :-


Roll no, name, deptt , course, year of passing
Assume that there are not more than 200 words students in the college.
A) Write a function to print names of all students who joined in a particular year?
B) Write a function to print the data of a student whose roll no is given?

Ans. struct student


{ int Roll no;
char name [50];
char deptt [20];
char course[50];
int yearofpassing;
};
struct student s[200];
a) Function to print student name of all students who joined in a particular year:
void print(int y)
{
for(int i=0;i<20;i++)
{
if(s[i ].yearofpassing==y)
Printf(“%s”,s[i].name)
}
}
b) Function to print data of a student whose roll no. is given
void print(int r)
{
int t=0;
for (int i=0;i<200;i++)
{
If(s[i].rollno==r)
{
printf(“%s”,s[i].name);
printf(“%s”,s[i].deptt);
printf(“%s”,s[i].course);
printf(“%s”,s[i].rollno);
printf(“%d”,s[i].yearofpassing);
t=1;
break;
}
}
if(t==0)
printf(“\n STUDENT DOES NOT EXIST”);
}

-----------------------------------------------<*><*><*>---------------------------------------------------------------------

Das könnte Ihnen auch gefallen