PART-A
Q1. Write a program to count the negative elements from the list using Arrays?
Ans 1.-
#include<stdio.h>
#include<conio.h>
void main()
clrscr();
int r[5],x,s=0;
for(x=0;x<=4;x++)
scanf(“%d”,&r[x]);
if(r[x]<0)
s++;
getch();
}
Q2. How can you differentiate a lower level array from the higher level array?
Ans 2.-
(1).Lower Level Arrays:- This type of array are single dimensional .we can also represent
one-dimensional array. In this arrays we can only single data item include in a single box
of an array.
For eg.-
(2).Higher Level Arrays:- In this Arrays which are more than two-dimensional array i.e.
two-dimensional, three-dimensional etc. These are called multi- dimensional arrays, in
which we can store multiple data items in a single row or in a column.
For eg.-
When we take take an array of character (char name[4][4]). So as per programming rule
we cannot store the word “chain” and “rain” can be stored in a single row/column of an
array. In other words we can say, only store our data in a multiple rows/columns.
Q3. Write a program that accepts an amount in figures and print that in words.
[Hint: - for an amount of Rs. 15200.50 it should output the string Rs. Fifteen
Thousand Two Hundred and Paisa Fifty only]
Ans 3.-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int b,pslast,plast;
scanf("%ld",&a);
printf("\nENTER PAISA:");
scanf("%d",&b);
s=a/10;
t=s%10;
r=a%10;
u=a/100;
v=u%10;
w=a/1000;
x=w%10;
y=a/10000;
z=y%10;
pslast=b/10;
plast=b%10;
printf("\nRs.");
switch(z)
case 1:
if(x==1)
printf(" ELEVEN THOUSAND");
else if(x==2)
if(x==3)
if(x==4)
if(x==5)
if(x==6)
if(x==7)
if(x==8)
if(x==9)
if(x==10)
break;
case 2:
if(x==1)
if(x==3)
if(x==4)
if(x==5)
if(x==6)
if(x==7)
if(x==8)
if(x==9)
if(x==0)
break;
case 3:
if(x==1)
else if(x==2)
printf(" THIRTY TWO THOUSAND");
if(x==3)
if(x==4)
if(x==5)
if(x==6)
if(x==7)
if(x==8)
if(x==9)
if(x==0)
break;
case 4:
if(x==1)
else if(x==2)
else if(x==4)
else if(x==5)
else if(x==6)
else if(x==7)
else if(x==8)
else if(x==9)
else if(x==0)
break;
case 5:
if(x==1)
else if(x==2)
else if(x==3)
printf(" FIFTY THREE THOUSAND");
else if(x==4)
else if(x==5)
else if(x==6)
else if(x==7)
else if(x==8)
else if(x==9)
else if(x==0)
break;
case 6:
if(x==1)
else if(x==2)
else if(x==3)
else if(x==5)
else if(x==6)
else if(x==7)
else if(x==8)
else if(x==9)
else if(x==0)
break;
case 7:
if(x==1)
else if(x==2)
else if(x==3)
else if(x==4)
printf(" SEVENTY FOUR THOUSAND");
else if(x==5)
else if(x==6)
else if(x==7)
else if(x==8)
else if(x==9)
else if(x==0)
break;
case 8:
if(x==1)
else if(x==2)
else if(x==3)
else if(x==4)
else if(x==6)
else if(x==7)
else if(x==8)
else if(x==9)
else if(x==0)
break;
case 9:
if(x==1)
else if(x==2)
else if(x==3)
else if(x==4)
else if(x==5)
printf(" NINTY FIVE THOUSAND");
else if(x==6)
else if(x==7)
else if(x==8)
else if(x==9)
else if(x==0)
break;
default:
break;
if(z==0)
switch(x)
case 1:
break;
case 2:
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
default:
break;
}
switch(v)
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
printf(" SEVEN HUNDRED AND");
break;
case 8:
break;
case 9:
break;
default:
break;
switch(t)
case 2:
printf(" TWENTY");
break;
case 3:
printf(" THIRTY");
break;
case 4:
printf(" FOURTY");
break;
case 5:
printf(" FIFTY");
break;
case 6:
printf(" SIXTY");
break;
case 7:
printf(" SEVENTY");
break;
case 8:
printf(" EIGHTY");
break;
case 9:
printf(" NINTY");
break;
case 1:
if(r==1)
printf(" ELEVEN");
else if(r==2)
printf(" TWELVE");
else if(r==3)
printf(" THIRTEEN");
else if(r==4)
printf(" FOURTEEN");
else if(r==5)
printf(" FIFTEEN");
else if(r==6)
printf(" SIXTEEN");
else if(r==7)
printf(" SEVENTEEN");
else if(r==8)
printf(" EIGHTEEN");
else if(r==9)
printf(" NINETEEN");
break;
default:
break;
switch(r)
case 1:
if(t!=1)
printf(" ONE");
break;
case 2:
printf(" TWO");
break;
case 3:
printf(" THREE");
break;
case 4:
printf(" FOUR");
break;
case 5:
printf(" FIVE");
break;
case 6:
printf(" SIX");
break;
case 7:
printf(" SEVEN");
break;
case 8:
printf(" EIGHT");
break;
case 9:
printf(" NINE");
break;
case 0:
if(r==0&&s==0&&t==0&&u==0&&v==0&&w==0&&x==0&&y==0)
printf(" ZERO");
break;
default:
printf("INVALID INPUT!!!");
/*WORKING ON PAISA*/
switch(pslast)
case 2:
printf(" TWENTY");
break;
case 3:
printf(" THIRTY");
break;
case 4:
printf(" FOURTY");
break;
case 5:
printf(" FIFTY");
break;
case 6:
printf(" SIXTY");
break;
case 7:
printf(" SEVENTY");
break;
case 8:
printf(" EIGHTY");
break;
case 9:
printf(" NINTY");
break;
case 1:
if(plast==1)
printf(" ELEVEN");
else if(plast==2)
printf(" TWELVE");
else if(plast==3)
printf(" THIRTEEN");
else if(plast==4)
printf(" FOURTEEN");
else if(plast==5)
printf(" FIFTEEN");
else if(plast==6)
printf(" SIXTEEN");
else if(plast==7)
printf(" SEVENTEEN");
else if(plast==8)
printf(" EIGHTEEN");
else if(plast==9)
printf(" NINETEEN");
break;
default:
break;
/*LAST EXTRACTION*/
switch(plast)
case 1:
if(t!=1)
printf(" ONE");
break;
case 2:
printf(" TWO");
break;
case 3:
printf(" THREE");
break;
case 4:
printf(" FOUR");
break;
case 5:
printf(" FIVE");
break;
case 6:
printf(" SIX");
break;
case 7:
printf(" SEVEN");
break;
case 8:
printf(" EIGHT");
break;
case 9:
printf(" NINE");
break;
case 0:
if(pslast==0&&plast==0)
printf(" ZERO");
break;
default:
printf("\nINVALID PAISA");
Q4. 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 4.- To initialize a three dimensional thread [4][3][3] we have to follow the following
syntax:
data_type variable_name[dim1][dim2][dim3];
int x[4][3][3];
for(a=0;a<=3;i++)
for(b=0;b<=2;j++)
for(c=0;c<=2;k++)
scanf(“%d”,&x[a][b][c]);
}
The first element of this array can be referred as x[0][0][0] and last element can be
referred as a[4][3][3].
PART-B
Q5. Can an array of pointers to strings be used to collect strings from the
keyboard? If not, why not? How, if yes?
Ans 5.- In my point of view we can’t use array of pointers to strings to collect strings
from the keyboard. Because ,
In c language we don’t have a string data type but it implements strings as single-
dimension character array. A string is terminated by a null character ‘\0’which is at the
end of the string. The character arrays are declared one character longer than the largest
string they can hold. For eg.- If we declare a string of character ch[10],it has 11
characters the last one is 11.
Q6. Give an example of a structure declaration without the use of a tag? What are
its advantages & disadvantages?
Ans 6.-
struct empinfo
{
int eid;
char ename[30];
char emobno[10];
}
e1,e2 ;
Here, e1 and e2 are the variables of structure empinfo. Because, the declaration of
variables are along the structure, the tag is not compulsary. hence,we can write the above
code as,
struct
{
int eid;
char ename[30];
char emobno[10];
}
e1,e2;
It has a great advantage because the code gets easier to understand and read, and we can
create as many variables i.e. persons info but on the other hand since the structure has no
name we cannot create a variable of the structure in the main() function if needed.