Program HelloWorld(output); var w,x,y,z : integer; begin writeln('input a number'); readln(x); w:=1; y:=0; z:=0; for x:=1 to x do begin z:=z+w; y:=y+1; w:=w*10+1; end; writeln('the sum is ', z); end.
Program HelloWorld(output); var i,num : integer; begin i:=0; writeln('Enter the number of terms u want to be calculated'); readln(num); If (num/round(num)) <> 1 then begin writeln('Please Input an intger'); end; if (num=1) then writeln('The answer is 1'); else while (i<=num) do begin num := num * 10^(i + 1; i:=i+1; end; writeln('The answer is ',num); end.
program YearsInRange; uses sysutils; var lowerLim, upperLim, yearCount, digitCount1, digitCount2: integer; repeatedDigit: boolean; begin writeln('Enter lower year limit:'); readln(lowerLim); writeln('Enter upper year limit:'); readln(upperLim); for yearCount := lowerLim to upperLim do begin repeatedDigit := false; for digitCount1 := 1 to length(inttostr(yearCount)) do begin for digitCount2 := 1 to length(inttostr(yearCount)) do begin if (digitCount1 <> digitCount2) and ((inttostr(yearCount))[digitCount1] = (inttostr(yearCount))[digitCount2]) then repeatedDigit := true; end; end; if repeatedDigit then writeln(inttostr(yearCount)); end; readln; end.
Program cinema_rate; var age, entrance_fee :integer; concession :boolean; begin writeln('Please input your age: '); readln(age); concession := false; if (age < 16) or (age > 65) then concession := true; if concession then entrance_fee := 500 else entrance_fee := 1000; writeln('Your entrance fee is ', entrance_fee); end.
{ This program takes a number of candidates and the votes they received in a election, and displays their data. Also, it finds out the winner of the election. Input: Candidate's name and the votes they got Output: Formatted data, total votes, and the winner's name Author: Dipiksha Shrestha } Program ElectionResults(output); Uses sysutils; // to use the format feature var count: integer = 0; i: integer; candidates: array[1..10] of string; votes: array[1..10] of integer; percent_array: array[1..10] of double; total_votes: integer = 0; max: double=0; indexOfWinner: integer= 0; procedure read_data(); { This procedure reads the data from the STDIN and saves them into their respective data-structures } var can_name: string; // name of the candidate vote: integer; // The vote they received begin for i := 1 to count do begin readln(can_name); {saves the candidates name into the variable} readln(vote); {saves the candidates votes into the variable} candidates[i] := can_name; {variable is stored in an candidates array} votes[i] := vote; {variable is stored in an votes array} // the total votes is calculated total_votes := total_votes+vote; end; end; procedure find_winner(); { This procedures finds the candidate who has the maximum votings } begin for i := 1 to count do begin // calculates the percentage of the votes they received percent_array[i] := (votes[i]/total_votes)*100; if((votes[i]/total_votes)*100>max) then // saves it to the max variable if it is the highest max := (votes[i]/total_votes)*100; end; end; procedure winner_name(); { Finds the name of the winning candidate based on the index of the winning percentage } begin for i := 1 to count do begin if(percent_array[i]=max) then indexOfWinner:=i; end; end; procedure write_output(); { This procedure writes the output to the screen in the formatted way. It includes the candidate name, their vote count, and the percentage. } begin for i := 1 to count do begin // Using Format to make the text visually appealing write(Format('%0:-30s', [candidates[i]])); write(Format('%d', [votes[i]])); writeln(Format('%25.2f', [percent_array[i]])); end; end; begin // Saves the total number of candidates into the variable, count readln(count); // The header of the output text writeln('Candidate' + ^i+ ^i+ ' Votes Received' + ^i + ^i +' % of Total Votes'); { Respective procedures are called that help read the data inputted by the user, save them, and display the result } read_data(); find_winner(); winner_name(); write_output(); // Remaining footer of the display text shown as output write('Total '); writeln(Format('%29d',[total_votes])); writeln('The winner of the election is ' + candidates[indexOfWinner] + '.'); end.
(* * Date: 03-29-2019 * Course: CSCI-3010 * Description: This program determines the winner of an election, given the total votes they have received.This program also calculates the percentage of votes an individual candidate received. The input are given in separate lines, number of candidates following the last name of candidates following number of votes they received and so on. Our output displays the input data(name and votes received) including the percentage of votes they received, total votes received and the name of winner. * On my honor, I have neither given nor received unauthorized help while completing this assignment. * NAME AND CWID: Bijay Raj Poudel ( 30096130 ) *) Program ElectionResults(output); //This program refers to unit 'sysutils' Uses sysutils; //global variables var candidateNames: array of string; var listOfVotes: array of integer; (*This function returns the percentage of fist parameter over the second parameter passed, i.e percentage of num1 in num2 *) function percentage(num1, num2: integer): real; (* local variable declaration *) var result: real; begin result := ( num1/num2 ) * 100; percentage := result; end; (*This function takes an integer array as parameter and returns the sum of all integers in thst array*) function totalVotes(var anArray: array of integer): integer; var sum, count :integer; begin sum := 0; for count:= 1 to length(anArray) do begin sum := anArray[count] + sum; end; totalVotes := sum; end; (*This function takes an integer array and return index of higest integer in the array*) function maxVote( var anArray: array of integer): integer; var highest, count: integer; begin highest := 1; for count := 1 to length(anArray) do begin if (anArray[count] > anArray[highest]) then highest := count; end; maxVote := highest; end; (*This procedure formats the output and displays all the details about candidates, including the winner of the election*) procedure toString(); (*local variable declaration*) var fmt, fmtInt, fmtDeci: string; var count: integer; begin //initialising the formatting regualar expressioins fmt := '%35s'; fmtInt := '%25d'; fmtDeci := '%33f'; writeln( 'Candidate' + format(fmt, ['Votes Received']) + format(fmt, ['% of Total Votes']) ); for count:= 1 to length(listOfVotes) do begin fmt:='%-12s'; writeln(format(fmt, [candidateNames[count]]), format(fmtInt, [listOfVotes[count]]), format(fmtDeci, [percentage(listOfVotes[count], totalVotes(listOfVotes))])); end; writeln(format(fmt, ['Total']), format(fmtInt, [totalVotes(listOfVotes)])); writeln('The winner of the election is ', candidateNames[maxVote(listOfVotes)], '.'); end; (*This procedure uses the data from STDIN and stores it arrays*) procedure userData(); (* local variable declaration *) var numberOfCandidates, count: integer; begin readln(numberOfCandidates); //setting array length SetLength(candidateNames, numberOfCandidates); SetLength(listOfVotes, numberOfCandidates); for count := 1 to 2*numberOfCandidates do begin //storing the candidates details in respective arrays of their type. readln(candidateNames[count]); readln(listOfVotes[count]); end; end; begin userData(); //procedure call to start the program toString(); //function call to display in candidate details and the winner. end.
Program Prime_No; var num,count,remainder:real; begin writeln('Input a number to check if it is a prime number.'); readln(num); count:=2; remainder:=1; repeat until count<=num and remainder=1 remainder:= num mod count; count:= count+1; if remainder=0 writeln('the number ',num,' is not a prime number.'); else writeln('the number ',num,' is a prime number.'); end.
Program exerxise_square_root; var guess:real; count,num:integer; begin writeln('input a num'); readln(num); writeln('what is your guess?'); readln(guess); count:=0; while count<>5 do begin guess:=(num / guess )+guess; guess:= guess / 2; writeln(guess:0:10); count:=count+1; end; writeln('sqrt of ',num,'is',guess:0:10); end.
Program Sqr_rt var Num,Guess,count,sqr_rt:real; begin writeln('Input the number to find the square root.'); readln(Num); writeln('Input your guess.'); readln(Guess); count:=0; repeat until count<5 begin sqr_rt:=guess; sqr_rt:=(Num/sqr_rt+sqr_rt)/2; Guess:=sqr_rt; count:=count+1; end writeln('The square root of',Num,'is',sqr_rt:0:10) end
Program TestPrime; var num, count, remainder:integer; begin writeln('Input a number to check whether it is a prime? '); readln(num); count:= 2; remainder:= 1; while (count <= num) and (remainder = 1) do begin remainder := num mod count ; count := count + 1; end; if remainder = 0 then writeln('The number ', num, ' is not a prime number') else writeln('The number ', num, ' is a prime number') end.
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more