Algoritmi de convertit bani in bere
Cand eram tanar copil am avut o atractie speciala fata de blogareala, programare si … bere. Mintea mea a clocit ceva aproape interesant, si anume un program de convertit bani in bere. Am dat peste articolul vechi si m-am gandit sa ii fac update ca sa fie la zi. Mentionez ca am luat un pret al berii egal cu 5ron.
Pascal:
program Beer;
var a,x,y:integer;
begin
writeln(‘cati lei vrei sa cheltuiesti?’);
repeat
write(‘Suma: ’);readln(a);
if a<=0 the write(‘nu poti sa platesti cu datorii!’);
until a>0;
x:=a div 5;
y:=a mod 5;
writeln(‘Din banii tai iti poti lua ‘,x,’ beri si iti mai raman ‘,y,’ lei rest!);
End.
C++:
#include <iostream>
using namespace std;
void main() {
cout << „Cati lei vrei sa cheltuiesti?” << endl;
int a;
do {
cout << „Suma: „;
cin >> a;
cout<<endl;
if(a <=0) cout << „Nu poti sa cumperi pe datorie!”<<endl;
}while (a <= 0);
cout << „Din banii tai iti poti lua ” << a / 5 << ” beri si iti mai raman ” << a % 5 << ” lei rest”;
}
Java:
import java.util.*;
public class Beer {
public static void main(String[] args) {
System.out.print(„Cati lei vrei sa cheltuiesti? „);
Scanner citire = new Scanner(System.in);
int s=citire.nextInt();
System.out.println(„Din banii tai iti poti lua ” + s/5 + ” beri si iti mai raman ” + s%5 + ” lei rest”);
}
}
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication
{
class Beer
{
static void Main(string[] args)
{
Console.Write(„Cati lei vrei sa cheltuiesti? „);
int s = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(„Din banii tai iti poti lua ” + s / 5 + ” beri si iti mai raman ” + s % 5 + ” lei rest”);}
}
}
Acesta este un pamflet! Oamenii normali si-au dat seama!