473,729 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Composite and Prime Numbers

this was my and my frineds little project in earlier classes,
the program seperates the composite and prime numbers in two sections
of the screen
=============== ======

/*
This program has been made by A & A Group.
Muhammad Ali: Roll # 1462 Class A-2 , B.Sc.(Hons.) in C.S.
Ashif Zubair: Roll # 1468 Class A-2 , B.Sc.(Hons.) in C.S.
ALL RIGHTS ARE RESERVED TO A & A Group.

CAUTION!
THIS PROGRAM IS PROTECTED BY LAWS AND COPYRIGHTS.
AS DESCRIBED IN TERM AND CONDITIONS SPECIFIED AT THE END.
COPYRIGHT 2003 - 2004, A & A GROUP. ALL RIGHTS ARE RESERVED.
*/

#include <iostream.h>
#include <conio.h>
#include <dos.h>

#define WASH 10
//ERASING SPEED OF NUMBERS IN MILLISECONDS. IT MUST BE AN INTEGER
VALUE.
#define SPEED 10
//THE SPEED IN MILLISECONDS FOR DISPLAYING THE COMPOSITE OR PRIME
NUMBERS.
#define SECOND 10
//TIME IN SECONDS, USED TO REDIRECT OR TERMINATE THE PROGRAM. MUST BE
AN INTEGER VALUE.
#define PAGE 2
//TIME IN SECONDS, BEFORTE THE LIST IS ERASED FROM SCREENS.MUST BE AN
INTEGER VALUE.
void composite (unsigned long int num); //Composite function
decleration.
void prime (unsigned long int num); //prime function deleration.
void erase (int , int); //Erase function decleration.
void display (void); //function which shows
displayed and remaining numbers.
void warning (void); //Warning function decleration
void a_a (void); //Function to display A&A Logo.
int agree (void); //Agreement function
declaration.

unsigned long int start,end,z,div isor; //For Filteration Section.
int p_row,p_coloum, p_page,p_total, //For Prime Section.
c_row,c_coloum, c_page,c_total, //For Composite Section.
term,time=PAGE; //For Terms and Conditions and Controlling Time.
char again; //Character Type Data for Iteration of
program.
// MAIN FUNCTION STARTS.
void main (void)
{
clrscr();
warning(); //Calling Function
int count;
for(count = SECOND;count>=0 ;count--)
{
gotoxy(19,34);
cout<<"YOU WILL BE REDIRECTED IN SECONDS : "<<count<<" \b";
delay(1000);
}
term = agree();
if(term==1)
{
do
{
p_row = c_row = 5;
p_total = c_total = 0;
p_page = c_page = 1;
p_coloum = 2;
c_coloum = 45;
clrscr();
cout<<"Enter Starting Value = ? ";cin>>star t;
gotoxy(45,1);
cout<<"Enter Ending Value = ? ";cin>>end;
gotoxy(10,3);
cout<<"PRIME";
gotoxy(53,3);
cout<<"COMPOSIT E";
gotoxy(50,48);
// Page number & total for composite.
delay(5);
cout<<"Total = "<<c_total;
gotoxy(65,48);
cout<<"Page # "<<c_page;
gotoxy(2,48);
// Page number & total for prime.
delay(5);
cout<<"Total = "<<p_total;
gotoxy(18,48);
cout<<"Page # "<<p_page;
if(start<=end&& start>=2)
{
for(z=start;z<= end;z++)
{
for(divisor = 2 ; divisor <= z ; divisor++)
{
if(z%divisor==0 && divisor != z)
{
composite(z);
break;
}
if(divisor == z)
{
prime(z);
break;
}
}
}
}
else
{
gotoxy(30,25);
cout<<"Invalid Input";
}
gotoxy(15,50);
cout<<"Enter [Y / y] to do again or [X / x] to quit = ? ";
cin>>again;
}while(again == 'y' || again == 'Y');
a_a();
warning();
for(count = SECOND;count>=0 ;count--)
{
gotoxy(19,34);
cout<<"PROGRAM WILL TERMINATE IN SECONDS : "<<count<<" \b";
delay(1000);
}
}
else
{
for(count = SECOND ; count >= 0 ; count--)
{
gotoxy(19,25);
cout<<"PROGRAM WILL TERMINATE IN SECONDS : "<<count<<" \b";
delay(1000);
}
}
}

/*
COMPOSITE FUNCTION DEFINATION STARTS.
*/
void composite (unsigned long int num)
{
gotoxy(c_coloum ,c_row);
delay(SPEED);
cout<<num;
c_row++;
c_total++;
display();
if(c_row == 47)
{
c_row = 5;
c_coloum += 5;
if(c_coloum == 70)
{
c_row = 5;
c_coloum = 45;
c_page++;
for(time=PAGE;t ime;time--)
{
gotoxy(20,50);
cout<<"New Composite page will load in "<<time-1<<" seconds...";
delay(1000);
}
erase (c_row,c_coloum );
c_row = 5;
c_coloum = 45;
}
}
gotoxy(50,48);
delay(5);
cout<<"Total = "<<c_total;
gotoxy(65,48);
cout<<"Page # "<<c_page;

}

/*
PRIME FUNCTION DEFINATION STARTS
*/
void prime (unsigned long int num)
{
gotoxy(p_coloum ,p_row);
delay(SPEED);
cout<<num;
p_row++;
p_total++;
display();
if(p_row == 47)
{
p_row = 5;
p_coloum += 5;
if(p_coloum == 27)
{
p_row = 5;
p_coloum = 2;
p_page++;
for(time=PAGE;t ime;time--)
{
gotoxy(20,50);
cout<<"New Prime page will load in "<<time-1<<" seconds...";
delay(1000);
}
erase (p_row,p_coloum );
p_row = 5;
p_coloum = 2;
}
}
gotoxy(2,48);
delay(5);
cout<<"Total = "<<p_total;
gotoxy(18,48);
cout<<"Page # "<<p_page;
}

/*
ERASE FUNCTION DEFINATION STARTS
*/
void erase (int row, int coloum)
{
int test = coloum;
while(1)
{
if(coloum != test + 25)
{
gotoxy(coloum,r ow);
cout<<" ";
delay(WASH);
row++;
if(row == 47)
{
row = 5;
coloum += 5;
}
}
else
break;
}
gotoxy(20,50);
for(test=20;tes t<=66;test++)
{
cout<<" ";
delay(5);
}
}

// Display , Remaining function Defination.
void display ()
{
gotoxy(30,21);
cout<<"Displaye d";
gotoxy(30,22);
cout<<"---------";
gotoxy(30,24);
cout<<(c_total+ p_total)<<"/"<<(end-start)+1;
gotoxy(30,26);
cout<<"Remainin g";
gotoxy(30,27);
cout<<"---------";
gotoxy(32,29);
cout<<((end-start)+1)-(c_total+p_tota l);
}

// Warning Function
void warning(void)
{
gotoxy(13,16);
cout<<" WARNING!";
gotoxy(13,20);
cout<<"THIS PROGRAM IS PROTECTED BY THE LAW'S AND COPYRIGHT";
gotoxy(13,22);
cout<<" AS STATED IN THE ABOUT SECTION IN SOURCE CODE";
gotoxy(13,24);
cout<<" ---------------------------------------------";
gotoxy(13,26);
cout<<" COPYRIGHT 2003 - 2004,\"A&A\" PROGRAMERS.";
gotoxy(13,28);
cout<<" ALL RIGHTS ARE RESERVED.";
}
void a_a(void)
{
clrscr();
gotoxy(10,1);
cout<<" IT'S AN";gotoxy(13,3 );
cout<<" ******* ******** ******** "
;gotoxy(13,4);
cout<<" ********** ********** ********** "
;gotoxy(13,5);
cout<<" *** *** *** *** *** *** "
;gotoxy(13,6);
cout<<" *** *** *** *** *** *** "
;gotoxy(13,7);
cout<<" ************ ***** ************ "
;gotoxy(13,8);
cout<<" ************ ******* ************ "
;gotoxy(13,9);
cout<<" *** *** **** *** *** *** "
;gotoxy(13,10);
cout<<" *** *** *** ***** *** *** "
;gotoxy(13,11);
cout<<" *** *** ******* *** *** *** *** "
;gotoxy(13,12);
cout<<" *** *** ********* *** *** *** "
;gotoxy(15,14);
cout<<" PRODUCTION! " ;
}

// TERMS AND CONDITIONS FOR USING THE PROGRAM.
int agree(void)
{
int law;
clrscr();
gotoxy(1,7);
cout<<"COPYRIGH T AND LAWS IN USING THIS PROGRAM"<<endl< <endl
<<"1. NO ONE OTHER THAN \"A&A\" GROUP IS ELIGIBLE TO MAKE ANY CHANGE
IN THIS "<<endl<<en dl
<<" PROGRAM UNLESS A WRITTEN PERMISSIONS IS OBRAINED FROM \"A&A\"
GROUP."<<endl<< endl<<endl
<<"2. THIS PROGRAM IS FREE TO USE AND DISTRIBUTE UNTILL ANY SORT OF
MODIFICATION"<< endl<<endl
<<" IS DONE INCLUDING CHANGING THE LAWS AND PROGRAMMERS
CREDIT."<<endl< <endl<<endl
<<"3. \"A&A\" GROUP WILL NOT BE HELD RESPONISIBLE FOR ANY
UDESIERABLE"<<e ndl<<endl
<<" EFFECT ON THE COMPUTER AFTER EXECUTING THIS
PROGRAM,"<<endl <<endl<<endl
<<"4. \"A&A\" GROUP IS ELIGIBLE TO MAKE CHANGE IN LAWS &
COPYRIGHT"<<end l<<endl
<<" WITH OR WITHOUT NOTIFICATION."< <endl<<endl<<en dl
<<"5. APPROPRIATE ACTION WILL BE TAKEN AGAINST THE PERSON
VOILATING"<<end l<<endl
<<" ANY OF THE CONDITIONS."<<e ndl<<endl<<endl
<<" COPYRIGHT 2003-2004, A & A - ALL RIGHTS ARE
RESERVED."<<end l<<endl<<endl
<<" YOU MUST AGREE THE TERMS AND CONDITION IN ORDER TO USE THE
PROGRAM"<<endl< <endl<<endl
<<"1: Agree ?\t 2: Disagree ?\n\nSelect Option 1 OR 2 ?\t";
cin>>law;
clrscr();
return law;
}
/*============== ==========*/

Jul 23 '05 #1
0 2400

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
8396
by: Dag | last post by:
Is there a python module that includes functions for working with prime numbers? I mainly need A function that returns the Nth prime number and that returns how many prime numbers are less than N, but a prime number tester would also be nice. I'm dealing with numbers in the 10^6-10^8 range so it would have to fairly efficient Dag
9
2715
by: Greg Brunet | last post by:
In doing some testing of different but simple algorithms for getting a list of prime numbers, I ended up getting some results that seem a bit contradictory. Given the following test program (testPrimes.py) with two algorithms that both check for primes by testing only odd numbers using factors up to the square root of the value, where Primes1 is based on all of the existing primes so far, and Primes2 is based on all odd numbers, I would...
11
7155
by: don | last post by:
Ok, this is a homework assignment, but can you help me out anyway...... I need a routine for figuring out if a number inputted by the user is a prime number or not...... all I'm asking for is Not the exact code ( well maybe a little) but the logic or algorithm to tell whether or not a number is prime....
0
1725
by: ETM11871 | last post by:
i need to develop a code that finds a prime right number between 2 and 100000. and print one line of text that indicates if the int. is right prime. i am in beginning programing so complex is complicated. we are on a functions chapter. i am usung the square root to find the prime. so far i have accomplished this but i cant fgure how to divide this by ten so i can find the right prime. i am using c. #include <stdio.h> #include <math.h> ...
25
3883
by: johnmsimon | last post by:
i need to develop a code that finds a prime right number between 2 and 100000. and print one line of text that indicates if the int. is right prime. i am in beginning programing so complex is complicated. we are on a functions chapter. i am usung the square root to find the prime. so far i have accomplished this but i cant fgure how to divide this by ten so i can find the right prime. i am using c. #include <stdio.h>
60
1950
by: rhle.freak | last post by:
Here is my code to generate prime numbers.It works absolutely fine when the range is *not very large*. However on initializing i with a large integer it produces erroneous results (some numbers ending in 5 ..which obviously cannot be prime numbers) can anyone please help me out with the reason?? /*Generate Prime Numbers*/ #include<stdio.h>
7
4901
by: newstips6706 | last post by:
1, 2, 3, 5, 7... PRIME Numbers ________________________________ Definitions What is a PRIME Number ?
7
4133
by: Caffiend | last post by:
Well, I've been picking at learning python, got tired of reading, and figured I'd try to replicate my prime number generator I wrote (with much TSDN forum help) in C++. I've hit a stumbling block... the program is supposed to print onscreen all the prime numbers between two numbers given to it, so if I put in 1 and 10, it should print out 1, 3, 5, 7 (I know, technically 1 isn't considered prime, and 2 should be on there, but otherwise...) ...
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.