+ 2

How to make this with c++ languange?

You will be given two numbers, x and y, in a line separated by a space. You have to print a line consists of x numbers starting from 1 and reset to 1 after y numbers. Input : The first line consists of two numbers x and y described above. 7 ≤ x ≤ 100 and 4 ≤ y ≤ x. Sample​ ​Input : 9 5 Output​ ​for​ ​Sample​ ​Input : 1 2 3 4 5 1 2 3 4

11th Oct 2017, 3:40 PM
Bela Kristianti
Bela Kristianti - avatar
4 Answers
+ 15
// ============================ // dependent numbers sequence // Done for: Bela Kristianti // By : Babak Sheykhan // ============================ #include <iostream> using namespace std; int main() { int x = 0; int y = 0; int i = 1; do { cout << "Enter x: "; cin >> x; } while (!(x >= 7 && x <= 100)); do { cout << "Enter y: "; cin >> y; } while (!(y >= 4 && y <= x)); cout << endl; // Loop using goto start: if (x > 0) { if (i <= y) { cout << i++ << " "; --x; } else i = 1; goto start; } else goto end; end:; } [https://code.sololearn.com/cF3K2X2c3AC3]
11th Oct 2017, 5:08 PM
Babak
Babak - avatar
+ 6
int i = 0; int x = int.Parse(Console.ReadLine()); int y = int.Parse(Console.ReadLine()); while(i < x) { Console.Write(++i + " "); if(i == y) i = 0; x = y; }
11th Oct 2017, 4:02 PM
Vukan
Vukan - avatar
+ 2
#include <iostream> using namespace std; int main() { int x, y; cout<<"Number of terms to print?"; cin>>x; cout<<"When to reset to 1?"; cin>>y; int i = 0; while(i <= x){ cout<<++i; if(i == y){ x -= i; i = 0; } } return 0; }
11th Oct 2017, 4:04 PM
Kartikey Sahu
Kartikey Sahu - avatar
+ 1
thank u everyone
12th Oct 2017, 2:26 AM
Bela Kristianti
Bela Kristianti - avatar