Sie sind auf Seite 1von 5

Roll no.

B46
Q1. Write a program to count the negative elements from
the list using Arrays.
Ans-
#inclclude<stdio.h>
#inclclude<conio.h>
Void main()
{
Int n,num[10],count=0,i;
Clrscr();
Printf(“enter the number of element ”);
Scanf(“%d”,&n);
For(i=0;i<n;i++)
{
Printf(“enter the num[%d]”,i);
Scanf(“%d”,&num[i]);
If(num[i]<0)
{
Count++
}
}
Printf(“count the negative number which is entered all
%d”,count);
Getch();
}
Q2. How can you differentiate a lower level array from
the higher level array?
Ans-
* Lower level array- it have low dimension(i.e. –one
dimensional,two dimensional ) ,is called lower level arry.
It’s application is easier than higher level array in c
language.
*higher level array- it have high dimension(i.e. –three
dimensional,four ,n dimensional array ) ,is called higher
level array. It’s application is very critical in c language.
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-
#include<stdio.h>
#include<conio.h>
Void main()
{
Float num[]=
{one,two,three,four,five,six,seven,eight,nine,ten,eleven,t
welve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen
ninteen,twenty,thirty,fourty,fifty,sixty,seventy,eighty,nint
y,hundred,thousand}

Int i, lastd;
Clrscr();
Printf(“enter the no. ”);
Scanf(“%d”,&num[i]);
If(num<20)
{
Printf(“%s”,num[i]);
}
If(num>=21&&num<99)
{
Lastd=num %10;
Num[i]=lastd+num[i];
Printf(“%s”,num[i]);
}
If(num>=100&&num<1000)
{
Lastd=num%10;
Num=num/10;
Num[i]=lastd+num[i]+num;
Printf(“%s”,num[i]);
}
Getch();
}

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-
#include<stdio.h>
#include<conio.h>
Void main()
{
Int arr[a][b][c],a,b,c;
for ( a =0; a< 2; a++ )
{
for (b=0; b < 1; b++)
{
for (c=0; c < 2; c++)
{
//Initialize each element array[a][b][c] = initialization;
}}}
1. The place of first element in the array arr[0][0][0]
2. The last place of the element in the array according to
question arr[2][1][2]

Q5. Can an array of pointers to strings be used to collect


strings from the keyboard? If not, why not? How, if yes?
Ans-

yes, an array of pointers to strings be used to collect


strings from the keyboard.
#include<stdio.h>
#include<conio.h>
void main()
{
char str1[10],str2[10];
clrscr();
int i=0;
int flag = 0;
printf("enter first string\n");
scanf("%s",str1);
printf("enter second string\n");
scanf("%s",str2);
while(str1[i]!='/0' && str2[i]!='/0')
{
if(str1[i]!=str2[i])
flag=1;
if(flag==1)
{
printf("not equal\n");
break;
}
if (flag==0)
{
printf("equal\n");
break;
}
}
}
Q6. Give an example of a structure declaration without
the use of a tag? What are its advantages &
disadvantages?
Ans-

#include<stdio.h>
#include<conio.h>
Struct
{
Char name[20],course[30];
Int course code,regno;
}
St1;
Void main()
{
Char name[20],course[30];
Int course code,regno;
Clrscr();
Printf(“\n enter the name”);
Scanf(“%s”,&st1 name);
Printf(“\n enter the course”);
Scanf(“%d”,&st1 course);
Printf(“\n enter the regno”);
Scanf(“%d”,&st1 regno);
Printf(“\n enter the name %s”);
Scanf(“%d”,&st1 name);
Printf(“%s %s %d %d “,name,course,course code,regno);
Getch();
}

Das könnte Ihnen auch gefallen