Кабинет информатики онлайн
Учитель информатики Косабуцкий Александр Николаевич

Простейшая программа


Pascal

programm z1;

var a,b,c: integer;

begin

read(a,b);

c:=a+b;

write(c);

end.


C++

#include <iostream>
using namespace std;
int main(){

int a,b,c;
cin>>a>>b;
c=a+b;
cout<<c;
system("pause");
return 0;}.

Pyton
a=int(input())
b=int(input())
c=a+b
print(c)

Цикл for

Pascal

programm z2;

var a,b,c,i: integer;

begin

read(a,b);

for i:=a to b do

begin

c:=c+i;

end;

write(c);

end.


C++

#include <iostream>

using namespace std;

int main(){

int a,b,s=0;

cin>>a>>b;

for (int i=a; i<=b; i++)

{

s+=i;

}

cout<<"s="<<s;

// system("pause");

return 0;}


Pyton
a=int(input())
b=int(input())
c=0
for i in range(a,b+1):
   c+=i

print(c)

Цикл while

Pascal

programm z3;

var a,b,c,i: integer;

begin

read(a,b);

i:=a;

while i<=b do

begin

c:=c+i;

i:=i+1;

end;

write(c);

end.


C++

#include <iostream>

using namespace std;

int main(){

int a,b,s=0;

cin>>a>>b;

i:=a;

while i<=b do

{

s+=i;

i++;

}

cout<<"s="<<s;

// system("pause");

return 0;}


Pyton
a=int(input())
b=int(input())
c=0
i=a
while i<=b:
   c+=i
   i+=1

print(c)


Ветвление if

Pascal

programm z4;

var a,b,c: integer;

begin

read(a,b);

if a>b then write(a-b) else write(b-a);

end.


C++

#include <iostream>

using namespace std;

int main(){

int a,b,c;

cin>>a>>b;

if (a>b) {c=a-b;} else {c=b-a;}

cout<<c;

system("pause");



return 0;}


Pyton
a=int(input())
b=int(input())
if a>b:
   print(a-b)
else:
   print(b-a)





This site was made on Tilda — a website builder that helps to create a website without any code
Create a website