введите с клавиатуры два числа N и M (N<M).определите и выведите на экран количество чисел между N и M, котроые являются номерами високосных годов.
#include <iostream>using std::cout;using std::cin;using std::endl;int main(){ int n, m, counter = 0; cout << "Enter n: "; cin >> n; cout << "Enter m: "; cin >> m; if(n >= m) { cout << "Invalid value" << endl; } else { while(n <= m) { if(n % 4 == 0) { counter++; } n++; } } cout << counter << " value" << (counter != 1 ? "s" : "") << endl; cin.get(); return 0;}
Вывод:
Enter n: 2000
Enter m: 2012
4 values
На Паскале:
program test;var n, m, counter: integer;begin write('Enter n: '); readln(n); write('Enter m: '); readln(m); counter := 0; while n <= m do begin if n mod 4=0 then counter := counter + 1; n := n + 1; end;writeln(counter, ' values');readln();end.
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int n, m, counter = 0;
cout << "Enter n: ";
cin >> n;
cout << "Enter m: ";
cin >> m;
if(n >= m)
{
cout << "Invalid value" << endl;
}
else
{
while(n <= m)
{
if(n % 4 == 0)
{
counter++;
}
n++;
}
}
cout << counter << " value" << (counter != 1 ? "s" : "") << endl;
cin.get();
return 0;
}
Вывод:
Enter n: 2000
Enter m: 2012
4 values
На Паскале:
program test;
var n, m, counter: integer;
begin
write('Enter n: ');
readln(n);
write('Enter m: ');
readln(m);
counter := 0;
while n <= m do
begin
if n mod 4=0 then
counter := counter + 1;
n := n + 1;
end;
writeln(counter, ' values');
readln();
end.