prime - char notprime = "not...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream.h> #include <math.h> void main () { int a, b; cout << "Type a number : "; cin >> a; cout << endl; try { if (a > 100) throw 100; if (a < 10) throw 10; throw a / 3; } catch (int result) { cout << "Result is : " << result << endl; b = result + 1; } cout << "b contains : " << b << endl; cout << endl; // another example of exception use : char zero[] = "zero"; char pair[] = "pair";
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: char notprime = &quot;not prime&quot;; char prime = &quot;prime&quot;; try { if (a == 0) throw zero; if ((a / 2) * 2 == a) throw pair; for (int i = 3; i &lt;= sqrt (a); i++) { if ((a / i) * i == a) throw notprime; } throw prime; } catch (char *conclusion) { cout &lt;&lt; &quot;The number you typed is &quot;&lt;&lt; conclusion &lt;&lt; endl; } cout &lt;&lt; endl; } }...
View Full Document

This note was uploaded on 02/26/2012 for the course MBA IT DOM1 taught by Professor Kviswanathan during the Spring '12 term at Indian Institute of Technology, Chennai.

Ask a homework question - tutors are online