Click here to Skip to main content
15,922,166 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to print the one to given number.with out using control statements and without using predefined methods
Posted

You might want to have a loot at this : http://stackoverflow.com/questions/4568645/printing-1-to-1000-without-loop-or-conditionals[^]

It's neither C nor Java, it's C++. The answer in the loop does not use any loop or condition.
 
Share this answer
 
Comments
Member 10351768 22-Oct-13 8:25am    
i posted one solution just see that one
C++
class Main{
int i=1;

public static boolean print(int max){
System.out.print(i)
i++;
boolean j=(i<=max)&&print(max);
return j;
}
public static void main(String[] args){
System.out.println("enter the number");
Scanner scanner=new Scanner(System.in);
int max=scanner.nextInt();
print(max);
}
 
Share this answer
 
v3
Comments
Captain Price 22-Oct-13 8:27am    
Wrong answer. This uses many methods.
If you want to print anything - be it on a piece of paper or a screen - you have to use at least one predefined method. The alternative is to write the whole operating system from scratch and that just isn't practical in a little textbox like this one.

In C to a console, it's easy:
C++
int i;
int maxnumber = 10;
for (i = 1; i <= maxnumber; i++)
   {
   printf("%d\n", i);
   }
Other systems or languages may require more work.


"
C#
no,control statements means loops,if statements,break,continue,return statements

with out using these things  i want the result

"



OK:
C++
printf("%d\n", 1);
printf("%d\n", 2);
printf("%d\n", 3);
printf("%d\n", 4);
printf("%d\n", 5);
printf("%d\n", 6);
printf("%d\n", 7);
printf("%d\n", 8);
printf("%d\n", 9);
printf("%d\n", 10);


You cannot make decisions without control statements of some form: all you can do is write code that runs from the start to the end with no branches, tests or loops - unless you accept an infinite loop. Even the "?" operator is a short form for an "if" control statement.
 
Share this answer
 
v2
Comments
Member 10351768 22-Oct-13 8:04am    
no,control statements means loops,if statements,break,continue,return statements

with out using these things i want the result
Captain Price 22-Oct-13 8:09am    
May I ask why ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900