Programming C++  «Prev 

Using iostream in C++ - Exercise

Objective: Rewrite the following C program, which uses printf() and scanf(), to a C++ program using iostream's cout and cin.

The C program

Here is the C program using printf() and scanf():
#include <stdlib.h>
#include <stdio.h>

int main(void){
  int i, n;
  printf("\n%s\n%s", 
   "Some randomly distributed integers will be printed.",
   "How many do you want to see? ");
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    if (i % 6 == 0)
      printf("\n");
    printf("%12d", rand());
  }
  return 0;
}

Paste the source code of your program below and click the Submit button when you are ready to submit this exercise.