Object

Write a program that prints 10 random ASCII characters.

Algorithm

  1. Declare integer variables i and a.
  2. Repeat FOR i = 0 to 9 by 1
    • a = ran()%256.
    • Write a as character.
    • [End of FOR loop.]
  3. Exit.

Flowchart

C++ Source Code

// program 74
#include<iostream>
#include <iomanip>
using namespace std;

int main()
{
  int i, a;

  for (int i = 0; i < 10; i++)
  {
    a = rand() % 256;
    cout << setw(5) << static_cast<char>(a);
  }
  return 0;
}

C Source Code

/*program 74*/
#include<stdio.h>
#include<stdlib.h>

int main()
{
  int i, a;
  for(i=0; i<10; i++)
     {
      a = rand()%256;
      printf("%5c", a);
     }
  return 0;
}

Output

    )    #    ╛    ä    ß    l    ╓    «    R    É
Design a site like this with WordPress.com
Get started