Computer Concept & Programming In C - Unit III - 18

Q.39. Write an algorithm to print all the even numbers and odd numbers between any given two integers N1 and N2 (N1 < N2) and also print the sum of all even numbers and odd numbers.                                                                                (AKTU. 2010 - 11)
Ans.
1. sum_even ¬ sum_odd ¬ 0
2. Write “Enter two integers”
3. Read N1, N2
4. i ¬ N1
5. While (i < = N2)
6.             do if (i mod 2 = 0)
7.                             then sum_even ¬ sum_even + i
8.                                             write i, “is even”, newline
9.                             else sum_odd ¬ sum_odd + i
10.                                          write i, “is odd”, newline
11. Write “sum of all even numbers”, sum_even
12. Write “sum of all odd numbers”, sum_odd.

Q.40. Write a program in C to display all the prime number between 100 and 1000.                                                                     (AKTU. 2012 - 13)
Ans.  
#  include <stdio. h>
# include <conio.h>
void main ( )
{
int i, j, c;
clrscr ( );
for (i = 100; i < 1000; i ++)
{
c = 0;
for (j = 2; j < i; j++)
if ((i % j) = = 0)
c ++;
if (c = = 0)
print f (“\n%d”, i);
}
getch ( );
}

Q.41. Differentiate between:
(i) System Software and Application Software
(ii) Compiler and interpreter                                          (AKTU. 2011 - 12)
Ans. (i) System Software: -
It is a software which is installed over the hardware or an operating system so that the hardware can be used by human user or another program in a convinient way. System software include software program like compiler, interpreter, assembler etc.
Application Software: -
It is a software which performs the task given by user by making use of underlying system software, operating system, drivers and hardware. Exmaples of application software are text processors, MS office. A C program written by a programmer and games etc.
(ii) Compiler and Interpreter: - A compiler is a language translator which translate a program written in a High Level Language into an equivalent program written in a low level language in one pass.
A compiler list all errors simultaneously if the program (source program) contains error otherwise it translates the program into an equivalent low level program also known as (target / object / executable) program.
Where as an Intrepreter is a system software which executes a program line by line and executes wherever it encounters an error. The execution resumes after the error has been rectified.
Differene between them: -
1. Compiler - An equivalent low-level program is generated.
Intrepreter - No program is generated rather it is executed.
2. Compiler - Translate a program from top - to down in one pass and list all errors simultaneously at the end.
Intrepreter - Executes a program line-by-line and it halts at the point where it finds an error.
3. Compiler - Low-level programs generated by compiler are optimized and executes fast.
Intrepreter - Programs are executed directly from source language, therefore execution is comparitively slower than that of compiled programs.
4. Compiler - Not good for error debugging.
Intrepreter - Good for error debugging.