do while loop includestdioh void main int num do printfPlease Input a number 1

Do while loop includestdioh void main int num do

This preview shows page 8 - 11 out of 11 pages.

/* do-while loop */ #include<stdio.h> void main() { int num; do { printf("Please Input a number < 1 or >= 10 > "); scanf("%d",&num); } // end of do loop while (num < 1 || num >=10) ; printf("Dear , Sorry ! Your number is out of specified range in program"); } // end of main Sample Output : Example 5 : Use of Increment and Decrement operators: /* Explanation on Increment, Decrement operators */ #include<stdio.h> void main() { Page 8 of 11
Image of page 8
int n, m, p, i = 3, j = 9; n = ++i * --j; printf("After the statement n = ++i * --j, n=%d i=%d j=%d\n", n, i, j); m = i + j--; printf("After the statement m = i + j--, m=%d i=%d j=%d\n",m ,i ,j); p = i + j; printf("After the statement p = i + j, p=%d i=%d j=%d\n", p, i, j); } // end of main Sample Output: Example 6 What is the output of the following program #include <stdio.h> int main(void) { int number, digits,sum; digits=sum=0; number=345; do { sum+=number%10; number=number/10; digits++; Page 9 of 11
Image of page 9
printf("%d*%d\n",digits,sum); }while(number>0); return 0; } Example 7: Nested Loops What is the output of the following program #include<stdio.h> void main(){ int i,j; for (i=2; i<=7; i+=3) { for (j=0;j <=i;j=j+3 ) printf("*"); printf("\n"); } printf("i=%d\nj=%d",i,j); } Example 8: What is the output of the following program #include<stdio.h> main( ) { int j, x=0; for (j=-2;j<=5;j=j+2) { switch(j-1) { case 0 : case -1 : x += 1; break; case 1: case 2: Page 10 of 11
Image of page 10
case 3: x += 2; break; default: x += 3; } printf("x = %d\n", x); } } Page 11 of 11
Image of page 11

You've reached the end of your free preview.

Want to read all 11 pages?

  • Spring '10
  • zaman
  • loop, Do while loop

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes