Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- alternate_number_series_v1.c
- Write a c Program that will print the number series vertically on screen:
- 10 1 9 2 8 3 7 4 6 5
- There, two series of numbers appear alternately
- first 10 9 8 7 6
- and second 1 2 3 4 5.
- There is no difference between loops in C,
- except that the do-while loop must be performed at least once.
- for loop
- https://www.tutorialspoint.com/cprogramming/c_for_loop.htm
- for ( init; condition; increment ) {
- statement(s);
- }
- while loop
- https://www.tutorialspoint.com/cprogramming/c_while_loop.htm
- init;
- while(condition) {
- statement(s);
- increment;
- }
- do-while loop
- https://www.tutorialspoint.com/cprogramming/c_do_while_loop.htm
- init;
- do {
- statement(s);
- increment;
- } while( condition );
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- int main(void)
- {
- int i, j, number_of_pairs=5;
- printf("\n Using for loop, the first way \n\n");
- for( i=0; i<number_of_pairs; i++ )
- printf(" %2d \n %2d \n", 10-i, i+1 );
- printf("\n Using for loop, the second way \n\n");
- for( i=10,j=1; j<=number_of_pairs; i--,j++ )
- printf(" %2d \n %2d \n", i, j );
- printf("\n Using while loop \n\n");
- i=10; // initial values
- j=1;
- while(j<=number_of_pairs) // condition
- {
- printf(" %2d \n %2d \n", i, j );
- i--; // decrement
- j++; // increment
- }
- printf("\n Using do-while loop \n\n");
- i=10; // initial values
- j=1;
- do
- {
- printf(" %2d \n %2d \n", i, j );
- i--; // decrement
- j++; // increment
- } while(j<=number_of_pairs); // condition
- return 0;
- }
Add Comment
Please, Sign In to add comment