Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

PROGRAMS

1.Program to display a message Hello,World.


with Ada.Text_IO; procedure Hello is begin Ada.Text_IO.Put("Hello,World!"); end Hello;

2.Program to run Simple Arithmetic Operation using Case Statements.


with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; procedure Arithmetic1 is First, Second : Integer; Operator : Character; begin Put ("Enter an expression: "); Get (First); Get (Operator); Get (Second); case Operator is when '+' => Put (First + Second, Width => 1); when '-' => Put (First - Second, Width => 1); when '*' => Put (First * Second, Width => 1); when '/' => Put (First / Second, Width => 1); when others => Put ("Invalid operator '");

Put (Operator); Put ("'"); end case; New_Line; end Arithmetic1;

3.Program to display Fibonacci Series using While Loop.


with Ada.Text_Io,Ada.Integer_Text_Io; use Ada.Text_Io,Ada.Integer_Text_Io; procedure Fibonacci is Number:Integer; Num_1:Integer; num_2:integer; num_next:integer; begin Put("enter the last number"); Get(Number); put("fibonacci series upto"); Put(Number);Put(" is: "); new_line(3); Num_1:=0; num_2:=1; while Num_2 <= Number loop Put(Num_2,5); Num_Next:=Num_1+Num_2; Num_1:=Num_2; Num_2:=Num_Next; end loop; end Fibonacci;

4.Program to display a message Good Morning or Good Afternoon using If-Else Statements.
With Ada.Text_IO; use Ada.Text_IO; procedure Greetings is Answer:Character; begin Put("Is it Morning(m) or Afternoon(a)?"); Get (Answer); if Answer='m' then Put_Line("Good Morning!"); else Put_Line("Good Afternoon!"); end if; end Greetings;

5.Program to display a message Good Morning or Good Afternoon using Assignment Statements.
With Ada.Text_IO; use Ada.Text_IO; procedure Greetings is Answer:Character; begin Put("Is it Morning(m) or Afternoon(a)?"); Get(Answer); if Answer='M' then Answer:='m'; elsif Answer='A' then Answer:='a'; end if;

if Answer='m' then Put_Line("Good Morning!"); elsif Answer='a' then Put_Line("Good Afternoon!"); else Put_Line("Please type 'm' or 'a'!"); end if; end Greetings;

6.Program to display a message Good Morning or Good Afternoon using Compound Conditions.
With Ada.Text_IO; use Ada.Text_IO; procedure Greetings is Answer:Character; begin Put("Is it Morning(m) or Afternoon(a)?"); Get(Answer); if Answer='m' or 'M' then Put_Line("Good Morning!"); elsif Answer='a' or 'A' then Put_Line("Good Afternoon!"); else Put_Line("Please type 'm' or 'a'!"); end if; end Greetings;

7.Program to display a message Good Morning or Good Afternoon using Case Statements.
With Ada.Text_IO; use Ada.Text_IO; procedure greetcase is Answer:Character; begin Put("Is it a Morning(m) or Afternoon(a)?"); Get(Answer); case Answer is when 'M'|'m' => Put_Line("Good Morning!"); when 'A'|'a' => Put_Line("Good Afternoon!"); when others => Put_Line("Please type 'm' or 'a'!"); end case; end greetcase;

8.Program to add the given two numbers.


With Ada.Text_IO,Ada.Integer_Text_IO; use Ada.Text_IO,Ada.Integer_Text_IO; procedure Sum is First :Integer:=24; Second:Integer:=36; begin Put("Enter Two Numbers:"); Get(First); Get(Second); Put("The Sum is");

Put("First+Second"); New_Line; end Sum;

9. Program to display your name, address, and phone number on different lines of the monitor.
with Ada.Text_IO; use Ada.Text_IO; procedure display is begin Put("John Q. Doe"); New_Line; Put("Anywhere, Anystate, USA, 12345"); New_Line; Put("(123) 456-7890"); New_Line; end display;

10.Program to say if a Number is Prime.


with Ada.Text_Io,Ada.Integer_Text_Io; use Ada.Text_Io,Ada.Integer_Text_Io; procedure Prime_No is Number,a,c:Integer; --count:=2; begin a:=0;c:=0; Put("enter a number"); Get(Number); for Count in 1..Number loop a:=(Number mod Count); if (a= 0) then C:=C+1; end if; end loop; new_line(2); Put("Given number"); put(number);put(" is "); if C=2 then

Put(" a prime number"); else Put("not a prime number"); end if; end Prime_No;

11.Program to print a Times table for any Positive Number.


with Ada.Text_Io,Ada.Integer_Text_Io; use Ada.Text_Io,Ada.Integer_Text_Io; procedure Times_Table is Number:Integer; Last_Num:Integer; Count:Integer; result:integer; begin Put("enter the number"); Get(Number); Put("enter the last number"); Get(Last_Num); for Count in 1..Last_Num loop Result:=Count*Number; Put(Count);Put(" * ");Put(Number); Put("=");Put(Result); New_Line; end loop; end Times_Table;

12. Program to convert a Fahrenheit temperature to Centigrade. The Fahrenheit and Centigrade is:Centigrade temperature = (Fahrenheit temperature - 32)/1.8.
with Ada.Text_Io,Ada.Integer_Text_Io,ada.float_text_io; use Ada.Text_Io,Ada.Integer_Text_Io,Ada.Float_Text_Io; procedure Tem_Conv is Temperature:Integer; Fahrenheit:Float; Centigrade:Float; begin Put("temperature "); Put("centigrade") ; New_Line; temperature:=-20; while Temperature <= 100 loop Centigrade:=float(Temperature-32)/(1.8); Put(Temperature); Put(" "); Put(Centigrade); New_Line; temperature:=temperature+10;

end loop end Tem_Conv;

You might also like