+ 2

How can we use a while loop by prompting the user for an integer and the system prints it 5 times only?

14th Jun 2019, 9:47 PM
Stephen Matara
Stephen Matara - avatar
4 odpowiedzi
+ 5
int i = 0; while(i < 5){ //some code i++; }
14th Jun 2019, 10:59 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Stephen Matara use input library class like Scanner, test the condition inside while would execute until the test condition is true. Finally use System output print and increment the integer by 1, from 1 to 5.
14th Jun 2019, 11:07 PM
Prantik Sarkar
Prantik Sarkar - avatar
0
Initilize another integer n, then read the value of n using scanf statement.
3rd Jul 2019, 5:41 PM
Jeevan Jose
Jeevan Jose - avatar
0
Int n; Int i; Printf("enter value for n\n") Scanf("%d", &n ); While(i<n) { //print statement I++; }
3rd Jul 2019, 5:46 PM
Jeevan Jose
Jeevan Jose - avatar