Sei sulla pagina 1di 9

Class VIII Final Term stored in this array?

Explain with the help of array


Practice Questions memory structure.
t) What are the differences between function
Q.1) ANSWER THE FOLLOWING QUESTIONS:- prototype and function definition? Give an
a) Amit wants to execute some instructions 10 times example also.
using ‘for loop’. complete the following statement u) Which statement is used to restart the loop?
that would enable him to do so: Explain with an example.
for(i= ;i<= ;i++) v) Simran wants to join three different strings ”DPS”,
b) Where do we put test condition in ‘do while loop’? ”Ranipur” and “Haridwar” stored in three
Give its syntax. different string variables. How can she join these
c) Explain ‘while loop’ with an example. three strings? Write a program also.
d) Why should we put break statement inside an ‘if’ w) What are the differences between entry-
statement? controlled loop and exit control loop?
e) What do you mean by scope of a function x) Find the user-defined and pre-defined functions
variable? Explain with an example. from the following list: add(), main(), xyz(), break()
f) How many rows and columns are created if an y) What is the use of getch() function in C and which
array is declared as int arr [5][3]. Draw its diagram header is used for this function?
also. z) What do you mean by an Array? How can you
g) What is the difference between function access array Elements?
prototype and function definition? aa) Write and explain the declaration statement of a
h) Do you think double dimensional array has more function which takes two arguments of integer
advantages over single dimensional array? Explain type and no return value.
with reason. bb) Why is do while loop known as bottom tested
i) Explain why do we put ‘continue’ statement inside loop? Explain with the help of an example.
an IF condition. cc) Write the importance of loops and also give an
j) Why do we call ‘DO WHILE LOOP‘ as bottom tested example?
loop? Explain with an example. dd) What is the difference between double
k) Can we put semicolon (;) while defining the test dimensional array and single dimensional array?
condition in ‘While Loop’? Give explanation for ee) What do you understand by the statement: “A
your answer. function is reusable”. Give an example of such a
l) Write the names of the three things important for function.
a loop. Explain any one. ff) Write any two Differences between break
m) How many rows and columns are created if an statement and continue statement in tabular
array is declared as int arr [3][5]. Draw its diagram form.
also. gg) Which function is used to compare two strings?
n) What happens when ‘break’ statement is executed Show how it works by writing a program.
in a loop? hh) Why do we use strlen() function?
o) What are the properties of a ‘DO WHILE LOOP’? ii) Write the indexes of a double dimensional array in
p) Is it necessary to put step increment or step tabular form, if it is declared as: int arr[3] [3].
decrement in ‘While Loop’? Give reasons for your jj) Suppose you have declared a function as: int
answer. sum(int,int); then which keyword will be
q) Do you think that there will be an error message if necessary in ‘function definition’ and why?
we define FOR LOOP as follows: kk) Why do we use strcmp() function? Give an
for (m=2,m>=1,m--) example.
r) What are C functions? Write any two types of user ll) What are user-defined functions? Explain all three
define functions. elements with the help of example.
s) Amit has declared an array with size of 5 rows and mm) Explain declaration of double dimensional
3 columns. How many elements are going to be arrays with index numbers in tabular form, if it is
declared as: int arr [4][2].

1
nn) Write the differences between Do while loop and double dimensional array over single dimensional
while loop in tabular form. array?
oo) What is the importance of return keyboard in lll) What do you understand by the following
functions? Give an example. statement: “A function is reusable”. Give an
pp) Name the three declarations that are important example also.
for a loop. Write the syntax of For loop. mmm) Write the difference between break statement
qq) What do you mean by function prototype? Explain and continue statement in tabular form.
with the help of an example. nnn) Which function is used to compare two
rr) Explain Arrays in C language. Write its types also. strings? Show how it works.
ss) Write and explain the syntax of “if-else” control ooo) Why do we use strlen() function?
flow statement. ppp) Write the indexes of a 2D array in tabular
tt) What is the difference between strcpy() function form, if it is declared as: int arr[3] [3].
and strcat() function? qqq) Suppose you have declared a function like: int
uu) Explain user defined function in your own sum(int,int); then which keyword will be
language. necessary in function definition and why?
vv) Why is do-while loop known as bottom tested
Q-2) Read the following questions carefully and write
loop? Explain its syntax.
your answers in the answer sheet:
ww) What is the difference between break
statement and continue statement? a) Write a program to print the following series
xx) Write and explain the declaration statement of a using ‘Do While Loop’: 1,3,5,7,9,11
function which takes no argument and no return b) Write a program to print the following series
value. using ‘while loop’: 125,27,1
yy) Why while loop is known as top tested loop? c) Write a program that accepts two strings from
Explain the example also. the user and checks whether both the strings are
zz) What do you mean by looping? of same length or not.
aaa) Can we enter multiple values of different data d) Write a program to initialize an array with five
type in single dimensional array? Give reason. integer elements and print the third element of
bbb) What do you understand by the following that array.
statement: ”A function can be called many times e) Write a program to print the following series
in a program”. Give an example also. using ‘for loop’: 3,6,9,12,15,18,21
ccc) Where do we use break and continue statement f) Write a function to print your school name10
in a program? Give an example. times.
ddd) Which function is used to join two strings? g) Write a program to print the following series
Show how it works. using ‘FOR LOOP’: 1,9,25,49,81
eee) Why do we use strcpy() function? h) Write a program that initializes an array of 7
fff) Write the indexes of a double dimensional array in elements and finds the sum of second element
tabular form, if it is declared as: int arr[2][3]. and fourth element.
ggg) Suppose you have declared a function like: i) Write a program to print the following series
float sum(int,int); then which keyword will be using ‘WHILE LOOP’: 125,64,27,8,1
necessary in function definition and why? j) To print 25 16 9 4 1 series by using any loop.
hhh) Write and explain the declaration statement of k) To initialize the array with the following
a function which takes two arguments of integer elements 3,6,9,12,15,18,21 and then find out the
type and no return value. sum of first, third and fifth elements of the array.
iii) Why do while loop is known as bottom tested l) To print the table of 5,10,15,20 using one user-
loop? Explain the example also. defined function only.
jjj) Write the importance of loops with an examples? m) To print the sum of a series by using Do while
kkk) We know an array contains multiple values of loop: s=1+5+9+13+17
same data type, so what is the advantage of n) To find out the square and cube of a number
using two different user-defined functions.

2
o) To enter two strings from the user and then
compare both strings. If both strings are equal
then print “well Done” otherwise print “Try
Again”.
p) To print the series: 1,4,9,16,25.
q) To copy a string from one variable to another
variable.
r) To make a function that accepts two numbers
from the user and displays the greater number.
s) To enter two strings, check the length of each
string and print the longer string.
t) To print the sum of 1 to 10 natural numbers.
u) Write a function to calculate the area of a
rectangle where the length and breadth are sent
as an argument.
v) To print 1,3,5,7,9,11,13,15,17,19 series using
continue.
w) Suppose, you are given following two strings:
A=”computer”, B=”science”. Write a program to
join above strings and find the length of the
concatenated string.
x) To initialize the array with the following
elements 4,9,6,8,10,15,26 and then find out the
sum of last three elements.
y) To print the table of 22 in table format “22*1=22”
using do while loop.
z) To print remarks for a student on the basis of
grade.
Grade Remarks
A- EXCELLENT
B- WELL DONE
C- WORK HARD
aa) To find the length of any string entered by the
user.
bb) To write a function to print table of 2.
cc) Print the series: 1,8,27,64,125.
dd) To compare two strings.
ee) To make a function that accepts two numbers
from the user and display the smaller number.
ff) To combine first name, middle name and last
name entered by a user.
gg) Print the series: 1,4,9,16,25.
hh) To copy a string from one variable to another.
ii) To make a function that accepts two numbers
from the user and display the greater number.
jj) To enter user name and password, if both are
correct then display the following message:
“Hello! Welcome to the first Stage of
Programming in C language”.

3
Q.2) Find out the errors in the following codes and { char name [40];
rewrite the corrected codes in your answer sheet: printf (“Enter a name : “);
gets (name);
a) # include <stdio.h>
puts (name);
void main( )
{ int i=10;
g) #include<stdio.h>
do;
void main( )
{ printf (“i=%d /t”,i);
{ int arr [3]={2,4,8,16};
i=i-3;
int i=3, j=0;
}while (i>0); }
while (i>=0)
{ j+=arr [i];
b) #include<stdio.h>
i--; }
void main( )
printf(“j=%d/n”,j);
{ int i:
for (i=1; i<=5; i++)
h) #include<stdio.h>
{
void main( )
if(i==3)
{ int pro (int,int);
continue for loop;
int main (void)
printf(“%d “,i);
{ int p=product (5,6);
printf(“%d”,p);
c) #include<stdio.h>
return 0; }
void main( )
int pro (int x, int y)
{ int arr [2] [2]=2,4,8,16;
{ x=2;
scanf (“%d”,&arr [0] [0] ;
return x*y; }
scanf(“%d”, &arr [0] [1];
scanf (“%d”,&arr [1] [0] ;
i) # include<stdio.h>
scanf(“%d”, &arr [1] [1];
#include<conio.h>
printf (“%d”,&arr [0] [0] ;
void main()
printf (“%d”,&arr [0] [1] ;
{ int p=20;
printf (“%d”,&arr [1] [0] ;
while do
printf (“%d”,&arr [1] [1] ;
{ printf(“%d\n”,p);
p=p-1;
d) ) #include<stdio.h>
}(p<0);
int add (int x;
getch();}
x=add (2,3,3);
printf ( “%d”,x);
j) # include<stdio.h>
{ int add (int a , int b )
#include<conio.h>
{ int s;
void main()
s=a+b;
{ int arr[5]={4,5,6,7,8};
return s; }
printf(“%d\n”,arr[4]);
printf(“%d\n”,arr[5]);
e) ) #include<stdio.h>
printf(“%d\n”,arr[6]);
#include<string.h>
getch(); }
void main( )
{ char strl [ ]=” Devanshi”;
k) # include<stdio.h>
if (strlength (strl)>=0 )
#include<conio.h>
puts (strl); }
void main()
{ int k=1;
f) #include<stdio.h>
for(k=1;k<10;k--)
void main( )
4
{ printf(“k=%d\n”,k); } void main()
getch(); } { int k=0;
k=(10,20);
l) void main() printf(“%d\n”,k);
{ int a[3.5]={4,8,5,3,2}; getch(); }
printf(“%d”,a[a]); } int sum(int x,int y)
{ return(x+y); }
m) void main()
{ int x=5; s) #include<stdio.h>
do; #include<conio.h>
{ printf(x); void main()
x=x+5; { int a=0;
}while (x<=50); } clrscr();
for a=0;
n) void main() clrscr();
{ char y={Examination”}; for(a=1;a<=50;a+1)
puts(y); } { printf(“%d\n”,a); }
getch(); }
o) #include<stdio.h>
t) #include<stdio.h>
#include<conio.h>
#include<conio.h>
void main()
void main()
{ int a=[3]={10,20,30};
{ int arr[5]={10,11,12,13,14};
clrscr();
int k;
printf(“%d\n”,a[2]);
clrscr();
getch(); }
for(i=0;i<=4;i++)
{ printf(“%d\n”,array[J]); }
p) #include<stdio.h>
getch(); }
#include<conio.h>
void main()
u) #include<stdio.h>
{ char s[10]:
#include<conio.h>
clrscr();
void main()
printf(“Please enter the string”);
{ int =0;
gets(s);
do loop {
printf(“Lenght of the string is “strlenght(s));
sum=sum+c;
getch(); }
c++;
}while(c<=10)
q) #include<stdio.h>
printf(“%d”,sum);
#include<conio.h>
getch(); }
void main()
{ int a=0;
v) #include<stdio.h>
clrscr();
#include<conio.h>
while(a<=50)
void main()
{ printf(“%d”,a++);
{ int a;
}do
clrscr();
getch(); }
printf(“\n Enter the value of a”);
scanf(“%d”,&a);
r) #include<stdio.h>
if(a>10) than
#include<conio.h>
{ printf(“No.is greater than 10”)
int sum(int,int);
getch(); }
5
w) #include<stdio.h> { printf(“%d”,c);
#include<conio.h> c++;}
void main() getch();}
{ int a={10,20,30};
clrscr(); b) Using While loop only.
printf(“%d\n”,a[2]); void main()
getch(); } { int a;
for(a=10;a<=20;a+=3)
x) #include<stdio.h> { if(a%2==0)
#include<conio.h> printf(“even”);
void main() else
{ char s[10]; printf(“odd”);
printf(“Please Enter the string “); printf(“\n programs end here”); }
gets(s);
printf(“Length of the string is “,length(s); c) Using any loop.
getch(); } void main()
{ clrscr();
y) #include<stdio.h> printf(“\n Middle Wing”);
#include<conio.h> printf(“\n Middle Wing”);
void main() printf(“\n Middle Wing”);
{ int a=0; printf(“\n Middle Wing”);
while (a<=50); getch();}
{ printf(“%d”,a++); }
getch(); } Q.4) Find the output of the following programs:
a) #include<stdio.h>
z) #include<stdio.h> #include <conic.h>
#include<conio.h> void main ( )
void main() { int i, p=0;
{ int k=0; for (i=0; i <10; i+=3)
k=avg(10,20); { p=i*i;
printf(“%d\n”,k); printf (“%d\n”,p); }
getch(); } getch ( ); }
int(int x,int y)
{ return((x+y)/2); } b) #include<stdio.h>
#include <conic.h>
aa) #include<stdio.h> void main ( )
#include<conio.h> { int i=5, q=0;
void main() while (i<10)
{ int a=0; { q=i*i++;
clrscr(); printf (“%d\n”,q); }
for(a=2;a<=10;a++1) getch ( ); }
{ printf(“%d\n”,a); }
getch(); } c) #include<stdio.h>
#include<conic.h>
Q.3) Convert the following programs: void main ( )
{ int arr [5]={12,14,18,26,34};
a) Using Do While loop only.
int i=0;
void main()
for(i=0;i<=5;i+=2)
{ int c=15;
{ printf(“%d”,arr [i]); }
whie (c<=25)
6
getch( ); } z=x+y ;
return (z); }
d) #include<stdio.h>
int max (int , int); i) #include<stdio.h>
void main ( ) #include<conio.h>
{ int a=2,b=8,c=3,d=0; void main()
d=max (a,max (b , c ) ) ; { int n=4532, rev=0;
printf (“%d”,d) ; } do
int max (int a ,int b ,) { rev=n%10;
{ return a > b? a: b ; } n/=10;
} while (n>0);
e) #include<stdio .h printf(“the no. is;->%d”,n);
#inculde <conic . h> getch(); }
void main ( )
{ char x [ ] =”Shilpee”; j) #include<stdio.h>
char y [ 20 ]=”Anjali”; #include<conio.h>
puts ( strcat (x,y) ) void main()
getch ( ) ; } int s=1;
for(s=1; s<=21;s+=3)
f) #include<stdio .h> { printf(“number %d\n”,s);
#include<string . h> if(s>5)
void main ( ) break; }
{ char strl [ ]=”Parul”; getch(); }
char str2 [ 10 ] ;
strcpy (str2 ,str1) ; k) #include<stdio.h>
if ( strcmp (strl , str2)===) #include<conio.h>
printf (“same/n”) ; void main()
else { int a=7;
printf (“Diffrent /n”) ; } while (a>1)
{ printf(“%d\n”, a-1);
g) #include<stdio .h> a=a-1; }
void main ( ) getch(); }
{ int i =1, j=3;
while(i <5) l) void main()
{ i++; { int g;
if (j==0) clrscr();
break ; for(g=45;g>=40;g--)
j--; } { if(g%3==0)
printf (“%d %d\n” , i,j) ; break;
getch ( ); } printf(“%d”,g);
} getch(); }
h) include<stdio .h>
int func (int , int ) ; m) void dps(int,int);
void main ( ) void main()
{ int x ; { clrscr();
x func (5 ,6) +100 ; dps(6,7);
printf (“%d” , x) ; } dps(10,5);
int func ( int x , int y ) getch(); }
{ int z ; void dps(int a,int b)

7
{ printf(“\n Sum=%d”, a+b); } void main()
{ int arr[4]={50,70,90,110};
n) void main() printf(“%d\n”,arr[3]);
{ clrscr(); getch(); }
int k[3][2]={{3,3},{6,6},{9,9}};
printf(“%d”,k[0][1]*k[1][1]); t) #include<stdio.h>
printf(“%d”,k[2][0]*k[0][1]); #include<conio.h>
getch(); } void main()
{ int a=0;
o) #include<stdio.h> clrscr();
#include<conio.h> for (a=3;a<=10;a--)
void city(void); { printf(“%d”,a); }
void main() getch(); }
{ clrscr();
city(); u) #include<stdio.h>
city(); #include<conio.h>
getch(); } void sum( int,int);
void city(void) void mul(int,int);
{ printf(“Hello ! India\n”); } void main()
{ clrscr();
p) #include<stdio.h> sum(9,18);
#include<conio.h> mul(6,3);
void main() getch(); }
{ int s[2][3]={{10,20,40},{50,60,70}}; void sum(int t,int y)
clrscr(); { printf(“%d\n”,t+y); }
printf(“%d”,s[0][0]*s[1][0]); void mul(int e,int f)
getch(); } { printf(%d\n”,e*f); }

q) #include<stdio.h> v) #include<stdio.h>
#include<conio.h> #include<conio.h>
void main(); void main()
{ char str1[5]=”Hello”; { int arr[5]={6,3,8,4,2};
char str2[5]=”World”; clrscr();
strcat(str1,str2); printf(“%d”,arr[0]+arr[1]+arr[2]);
puts(str1); printf(“\n%d”,++arr[3]);
getch(); } getch(); }

r) #include<stdio.h> w) #include<stdio.h>
#include<conio.h> #include<conio.h>
void main() #include<string.h>
{ int k=0; void main()
for(k=1;k<=5;k++) { char name[5]=”DPS”;
{ if(k==2) char sname[10]=”RANIPUR”;
{continue;} clrscr();
printf(“%d\n”,k); strcat(sname,name);
} getch(); } puts(sname);
getch(); }
s) #include<stdio.h>
#include<conio.h>

8
x) #include<stdio.h> getch ( ); }
#include<conio.h> void wel (void)
void main() { printf(“Welcome! india\n”); }
{ int c=1;
while (c<=10) dd) #include<stdio.h>
{ printf(“%d”,2*c); #include<conio.h>
c=c+1; } void main()
getch(); } { int s [2][3]={{10,20,40},{50,60,70}};
clrscr();
y) #include<stdio.h> printf(“%d”,s[1][1]*s[1][1];
#include<conio.h> getch(); }
void main()
{ int arr[2][2]={{6,9},{3,8}}; ee) #include<stdio.h>
clrscr(); #include<conio.h>
printf(“%d\n”,arr[0][0]); void main()
printf(“%d\n”,arr[0][0]+ arr[0][1]); { char str1[4]=”Save”;
getch(); } char str2[6]=”Energy”;
char str3[10]=strcat(str1 , str2);
z) #include<stdio.h> puts(str3);
#include<conio.h> getch(); }
void main
{ int i,n=15; ff) #include<stdio.h>
for(i=1;i<=n;i+2) #include<conio.h>
{ printf(“%d”,i); } void main()
getch(); } { int k=0;
for(k=1;k<=5;k++)
aa) #include<stdio.h> { if(k==2)
#include<conio.h> {break;}
void main() printf(“%d\n”,k);
{ int i=1; i<=10;i++) { } getch(); }
if(i % 2==1)
{ continue; } gg) #include<stdio.h>
printf(“%d\n”,i); } #include<conio.h>
getch(); } void main()
{ int arr [4]={50,70,90,110};
bb) #include<stdio.h> printf(“%d\n”,arr[2]);
#include<conio.h> getch(); }
void main()
{ int arr[3][2]={{2,1},{3,7},{8,5}};
clrscr();
printf(“%d\n”,arr[2][0]+arr[1][1]);
getch(); }

cc) #include<stdio.h>
#include<conio.h>
void wel(void);
void main()
{ clrscr();
we( );