0% found this document useful (0 votes)
3 views3 pages

Forloop Output

The document outlines the outputs of various for loop statements in Java, detailing the expected results for each loop iteration. It also includes a question about which loops execute a specific number of times, with answers provided for both 5 and 10 iterations. Additionally, there is a function for calculating the factorial of a number with a specific example.

Uploaded by

P21
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Forloop Output

The document outlines the outputs of various for loop statements in Java, detailing the expected results for each loop iteration. It also includes a question about which loops execute a specific number of times, with answers provided for both 5 and 10 iterations. Additionally, there is a function for calculating the factorial of a number with a specific example.

Uploaded by

P21
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

For loop output

Write the output


Statement Output

1 int i; 1
for (i=1;i<=4;i++) CNS
{ 2
[Link](i); CNS
[Link]("CNS"); 3
} CNS
4
CNS

2 int i; 1
for (i=1;i<=4;i++) 2
[Link](i); 3
[Link]("CNS"); 4
CNS

3 int a; 15
for ( a=5;a<15;a+=2);
[Link](a);

4 int a; 17
for (a=5;a<=15;a+=2);
[Link](a);

5 for (int i=1;i<=3;i++) 1


{ CNS
[Link](i); 2
[Link]("CNS"); CNS
} 3
CNS

6 int i; -1
for (i=10;i>=0;i--);
[Link](i);
7 int i; 0
for (i=10;i>0;i--);
[Link](i);

8 int i,s=0; 0
for (i=0;i<=3;i++) 1
{ 3
s=s+i; 6
[Link](s);
}

9 for (int s=0;s<=3;++s) 2


{ 5
s=s+2;
[Link](s);
}

10 int s; 6
. for ( s=0;s<=3;++s)
s+=2;
[Link](s);

11 int i; 1
for (i=0;i<10;i+=2) 4
[Link](++i); 7
10

12 for (int i=0;i<10;i+=2) 0


[Link](i++); 3
6
9

13 int s=0,i; 0
for ( i=0;i<=5;i++) 1
{ 3
s=s+i; 6
[Link](s); 10
} 15
14 int a,b; 1
for(a=1,b=5;a<5;a++,b--) 5
{ 2
[Link](a); 4
[Link](b); 3
} 3
4
2

15 public void fact(int n) 24


{
int f=1,j;
for(j=n;j>=1;j--)

f=f*j;
[Link](f);

If n==4,what will be the output

1. Which of the following loops execute 5 times?


a) for (i=1;i<=5;i++)
b) for (i=0;i<5;i++)
c) for (i=0;i<=4;i++)
d) all the above
Answer :all the above
2. Which of the following loops execute 10 times?
a) for (j=14;i<=42;j+=3)
b) for (j=10;j<20;j+=2)
c) for (j=5;j<=15;j++)

Answer:a) for (j=14;i<=42;j+=3)

You might also like