Question...
An approximate value of pi can be calculated usong the series given below:
Pi=4[1-1/3+1/5-1/7+1/9…+((-1)n)/(2n+1)]
((-1)n)=n is a power for-1(for your information)
Write a C++ program to calculate the approximate value of pi using this series.The program takes an input n that determines the number of terms in the approximation of value of pi and outputs the approximation.Includes a loop that allows the users to repeat this calculation for new values n until the user says she or he wants to end the program. - #include <iostream>
-
using namespace std;
-
-
void prime_num(int);
-
int main()
-
{
-
int retry;
-
-
do
-
{
-
int x = 100;
-
prime_num(x);
-
}
-
-
void prime_num( int n)
-
{
-
bool Prime=true;
-
-
for ( int k = 3; k <= n; k++)
-
{
-
for ( int j = 2; j <= n; j++)
-
{
-
if ( k!=j &&k % j == 0 )
-
{
-
Prime=false;
-
break; // stop looping
-
}
-
}
-
if (Prime)
-
{
-
cout << " do you want to repeat the process?(Yes/No)"\n";
-
cin >> retry;
-
} while ( retry='Y'|| retry='y')
-
-
cout << " Prime: " << k << "";
-
}
-
Prime = true;
-
}
-
-
}
this coding cannot give me an output n have many error.
8 4260 Banfa 9,065
Expert Mod 8TB
Interestingly you problem seems to be about calculating PI but the could you have posted appears to be code to find prime numbers.
May be you would like to
1. Read the Posting Guidelines particularly the part about posting coursework.
2. Post the code actually related to the problem, or post the problem actually related to the code.
i'm sorry
the coding is for prime question
but there is no output
this is the question for the prime coding
Write a program that finds and prints all the numbers between 3 and 100.A prime number is a number such that one and itself are the only numbers that evenly divide it(eg.,3,5,7,11,13,17,.....)
one way to solve this problem is to use a doubly nested loop.The outer loop can iterate from 3 to 100 while the inner loop checks to see if the counter value for the outer loop is prime.one way to see if number n is prime is to loop from 2 to n-1 and if any of these numbers evenly divides n,then n cannot be prime.if none of the value from 2 to n-1 evenly divide n,then n must be prime.
can you help me??
I'm sorry to disturb you.
why the program no output?
is it false??
i'm sorry
the coding is for prime question
but there is no output
this is the question for the prime coding
Write a program that finds and prints all the numbers between 3 and 100.A prime number is a number such that one and itself are the only numbers that evenly divide it(eg.,3,5,7,11,13,17,.....)
one way to solve this problem is to use a doubly nested loop.The outer loop can iterate from 3 to 100 while the inner loop checks to see if the counter value for the outer loop is prime.one way to see if number n is prime is to loop from 2 to n-1 and if any of these numbers evenly divides n,then n cannot be prime.if none of the value from 2 to n-1 evenly divide n,then n must be prime.
can you help me??
I'm sorry to disturb you.
why the program no output?
is it false??
There is no outoput at all?
what should i do to get the output?
it must have an output, isn't it?
Banfa 9,065
Expert Mod 8TB
Your posted code does not compile because you have defined the function prime_num inside the function main and C/C++ does not support nested function definitions.
You need to begin by moving prime_num outside main.
Your posted code does not compile because you have defined the function prime_num inside the function main and C/C++ does not support nested function definitions.
You need to begin by moving prime_num outside main.
I move the prime_num already but it still cannot get the output.
There is no output at all.Please help me..
Banfa 9,065
Expert Mod 8TB
You code is such that your assertation that you have fixed the problem with location of prime_num in the posted code does not enable us to tell what the resulting code is as there were several other errors.
As Banfa said, there are countless errors in the posted code. Not only is prime_num defined inside main, but it is between the end bracket and the while () of your first loop. Also, the prime_num function is not finished - after you close the second if() statement, you continue with the while(). Rearrange the code to make sense, finish the main() and prime_num() functions, and then see if you are still getting bad output.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jason |
last post by:
hello,
i am new to PHP, so go easy.
I am using the examples in the book:
PHP: Your Visual Blueprint For Creating Open Source, Server Side Content
In the section where they talk about...
|
by: Rv5 |
last post by:
Let me start out by saying this is actually c++ code, but I couldn't get
anyone on the c++ newsgroup to respond, and Id really like opinions. The
code works fine, so Im not looking for syntax...
|
by: Steve Clay |
last post by:
I have a small C program for a college course. It is meant to encrypt
and decrypt lower case letters and leave spaces as spaces. I can't
get it to run properly as I think I have a problem in the...
|
by: Bharat Shetty |
last post by:
project doubt
1) ping all defined machines in the network from time to time, and
alert (by an indicator on a web page or screen) when some machine is
down
(2) periodically check HTTP and FTP...
|
by: Gary |
last post by:
Hello,
I'm hoping someone can shed some light on why my report does not output
the same results as shown in preview mode, which is to move the
position of a check box based on a field value (see...
|
by: silverchrono |
last post by:
this is my first semester in C
and im trying to figure out how to reset a counter.
heres why im trying to do.
void text()
59 printf("You can end entering the text by using '#'\n");
60 int...
|
by: kirubagari |
last post by:
I want to check the arrangement of data in this order from byte 49 to mFile size(END OF FILE).
04 FF _ _ _ _ _04 FF _ _ _ _ 04 FF _ _.
_ __ 04 FF _ _ _ _ 04 FF _ _ _ _ 04 FF
Actually the values...
|
by: magicofureyes |
last post by:
Hello Guys im a just a new user and i dnt knw much abt Xml i want to upload a new template in Blogger so got some free coding but when i save this code in Blogger template it say
'''' Your...
|
by: phanimadhav |
last post by:
Hi,
i am working on the coding part which is based on jsp/html.As im fresher i am facing some problems with the code.so,can u please guide me..This is the error which i ve got...please have a...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |