Refer Sum of 1 to 100 numbers
1 : State the output of the below given programs :
(a)
Answer :
Will this loop be entered
Was the loop entered
==================================================================================
(b)
Answer :
Will this loop be entered
Print this,if the loop is entered...j=5
Is the Boolean j 6 still true?
No,Because j is now 7
==================================================================================
(c)
Answer :
The for(;;)loop is really quite easy to use.
\'ve said this once
The for(;;)loop is really quite easy to use.
\'ve said this twice
What I say 2 times must be true!
==================================================================================
2 : Replace the for(;;) statement in the program 1(a) above by :
for (i=1;sum=0;i<101;i++)
Realize that the comma operator can be used with the expressions controlling a for(;;) statement. That in fact is its most common usage.
Observe that the value of the loop index is retained on exit from the loop.
==================================================================================
3 : In Program 1(c) above, can the && operator be replaced by the || operator ?
Can it be replaced by the comma operator ?
Are the parentheses around sum+=i++ required ?
==================================================================================
4 :
(Will continue...)
===========================================================
1 : State the output of the below given programs :
(a)
##include<stdio.h> #include<conio.h> void main() { clrscr(); int j=5; for (printf("Will this loop be entered\n");j<2;j=1) printf("Print this,if the loop is entered..."); printf("Was the loop entered\n"); getch(); } |
Answer :
Will this loop be entered
Was the loop entered
==================================================================================
(b)
#include<stdio.h> #include<conio.h> void main() { clrscr(); int j=5; for (printf("Will this loop be entered\n");j<6;j=7) printf("Print this,if the loop is entered...j=%d\n",j); printf("Is the Boolean j 6 still true?\n%s",j<6?"Yes,":"No,"); printf("Because j is now %d\n",j); getch(); } |
Answer :
Will this loop be entered
Print this,if the loop is entered...j=5
Is the Boolean j 6 still true?
No,Because j is now 7
==================================================================================
(c)
#include<stdio.h> #include<conio.h> void main() { clrscr(); int j; for(j=0;j<2;j++) { printf("The for(;;)loop is really quite easy to use.\n"); printf("I\'ve said this %s.\n",j==0?"once":"twice"); } printf("What I say %d times must be true!\n",j); getch(); } |
Answer :
The for(;;)loop is really quite easy to use.
\'ve said this once
The for(;;)loop is really quite easy to use.
\'ve said this twice
What I say 2 times must be true!
==================================================================================
2 : Replace the for(;;) statement in the program 1(a) above by :
for (i=1;sum=0;i<101;i++)
Realize that the comma operator can be used with the expressions controlling a for(;;) statement. That in fact is its most common usage.
Observe that the value of the loop index is retained on exit from the loop.
==================================================================================
3 : In Program 1(c) above, can the && operator be replaced by the || operator ?
Can it be replaced by the comma operator ?
Are the parentheses around sum+=i++ required ?
==================================================================================
4 :
(Will continue...)
===========================================================
No comments:
Post a Comment