Thursday, 30 July 2015

Basic pascal programing language codes

Write a program that reads two integers and then displays
    a) Their product
    b) Their quotient when the first is divided by the second

program product(input, output);
uses crt;
var a,b,c,d:integer;
begin
writeln(‘Enter an integer’);
readln(a);
writeln(‘Enter an integer’);
readln(b);
c=a*b;
writeln(c)
d:=a div b;
writeln(d)
readln;
 end.

  
Write a program that uses nested loop to find prime numbers from 2 to 50.

Program nestedprime;
uses crt;
var
i,j:=integer;
begin
  for j:=2 to 50 do
begin
   for j:=2 to i do
       if (i mod j)=0 then
          break;
if(j=1) then
writeln(i , ‘is prime’);
end;
end.


Write a program to calculate the population of a city at the end of each year from
1990 to 2000. Use the following assumptions:
a. Initial population at the end of 1989 = 5 million
b. Yearly death ratio = 3%
c. Yearly birth ratio = 7%

program population;
uses crt;
var
 P,B,D:=integer;
P := 5000000.0 ;
begin
for  i := 1990 to 2000 do
begin
B:= 0.07 * P;
 D:= 0.03;
P:= P + B - D;
Writeln(‘Details of total population each year is’);
writeln(i:10, P:20:2);
end;
end.