C/C++ :: Make Program To Square Numbers From 1 To 20
Oct 21, 2012
I want to make program to square the numbers from 1 to 20. i have written this program, it's running but not giving the required answer.i think it is giving a garbage value...
void main(void)
{int a;
int b;
b=a*a;
for (a=1; a<21; a++)
{printf("%d",b);
printf("the square is%d=b");
}
getche();}
I've reached a point in "Jumping into C++" where I need to make a program that converts input numbers into their word equivalent.
So far I've made it work for numbers 0-9999. I've tried implementing 10000-99999 but there are problems with the order of the words printed (57865 would print fifty thousand seven thousand eight hundred sixty five). But besides that, the program is absolutely enormous (for me) and I'm wondering if it can be shortened. Keep in mind I can only use loops and if statements so far. Here it is:
Display the remainder of the square of numbers from 100 to 10. This square of numbers must be divisible by the numbers from 100 to 10 respectively. what i need to in this
Write a function which takes two parameter of integer type and both parameters are positive integer. These number should be provided by the user of your program. The first parameter is lower than the second parameter. You function should be able to calculate the sum of the square of each of the numbers between the two inputs and should display that. Please write a main function to display the working of your function. Call the function at least three times by using some loop in the main function.
This is what I came up with but it is not correct:
#include <iostream> using namespace std; void sumsquares(int number1, int number2) { int sum = 0; for(int i = number1; i<number2; i++) sum =sum+ i*i; cout<<"The Result is: "<<sum<<endl;
I'm currently trying to write a program that takes an integer input from the user and displays that number of square-free numbers. I've gotten most of the program to work, but I encounter an error during the noSquare function that causes it to print incorrectly.
A square-free number is a number that is not evenly divisible by the square of any prime number. It's hard to see the bold in the code area, but it begins after the "//I think below is where the problem is"
#include <iostream> #include <vector> using namespace std;
I'm currently trying to write a program that takes an integer input from the user and displays that number of square-free numbers. I've gotten most of the program to work, but I encounter an error during the noSquare function that causes it to print incorrectly. I have bolded the area where I believe the problem is what I am doing wrong.
The problem with the program is that it prints ALL numbers from 1 to the input number instead of just the square-free.
A square-free number is a number that is not evenly divisible by the square of any prime number ....
#include <iostream> #include <vector> using namespace std; bool noSquare (int num); //Function to determine if the number is square-free vector<int> getPrimes(int num); //Function to get a vector of all primes below num bool isPrime (int number); //Function to determine if individual numbers are prime int main()
[Code]...
By the way, the in the middle of the code was me trying to bold a section, not an actual part of the code. I can't seem to find where to edit my original post.
I tried to check the rational or irrational numbers after we take the square root. i dont get the formula. for eg. squareroot of 64 is 8 and it is rational. square root of 2 is irrational. how to check it in c++..
I have tried writing a code which takes two numbers from the user and calculates their square root then the roots are added up to return the sum. The program is coming out with loads of errors.
#include<iostream> #include<cmath> float main(){ using namespace std; float m1,m2,m3,m4,m5;
I am able to display a filled and hollow square by themselves, but I can't seem to be able to get them side by side.
So this is my code so far:
[/ #include <iostream> using namespace std; int main()
[Code]....
I can get the hollow square to show up, but the first square just shows up as a single line instead of a square. It seems that it ignores the first if statement in the second loop. I've tried not using an if statement in the second loop but it didn't seem to work either.
I can't find a way to square and cube the number I want, which the number will show in the notepad. Is there a way to cube and square a number in my program??
I am writing a program to find the square root of a number. I am using the Newton-Raphson method..Just to clarify a bit of the code.. fabs(1/(x+1)) < 0.001 is to check for relative error..
EXAMPLE: for user entry of 100 if the iteration process ends in 10.055 the answer will return as 10 which is correct. But it isn't doing that.
It compiles I then proceed to run it..prompts me "Enter a number to find the square root of: I type 100 then hit enter...
"The square root of 100 is -1077834936"
My first time writing a program from complete scratch.
And I know there is a sqrt() function...just wanted to write my own.
Code:
#include <stdio.h> #include <math.h> double mysqrt(double a); int main() { double a, result; printf("Enter a number to find the square root of: ");
B. Circle in a Square Write a C++ program that will ask the user to enter the area of a square. Then the program will display the biggest area of a circle that will fit in a given square. Using math.h library is not allowed.
I'm working on a c program that generates approximations of square roots based on newton raphson method. I worked out the approximations with another method I learnt and I know this program does fine. But I don't get the concept of epsilon. Below is the code for the program
Code:
#include<stdio.h> // function to compute absolute value float absoluteValue(float x) { if(x < 0) x = -x;
[code]....
The text I worked this code from uses the epsilon value arbitrarily. how is the epsilon value selected? I tried using this formula to derive the square root of 45. On paper I can go as far as 6.8 something. But once this value is reached it's still bigger than epsilon, so shouldn't the code keep running? The program generates 1.41 for 2, but since it could go further why does the while loop in squareRoot function terminate?
Create a user-defined program that will compute the price per square inch of a cake using an “overloading”. The cake could be a circle or a square type. In the main function, ask for the price of a circle cake and its diameter, while for the square cake, ask for the price, its length and width. The process must be done inside the different function of each cake. (Note: two sub function for the computation of a circle and a rectangle)
Note that when I made this program something weird happen. After inserting the name, all things follow.
<code> #include "stdafx.h" #include <iostream> using namespace std; double areaRectangle(int l, int w); double radiusCircle(int r);
Assuming you have an array of these values x=[16,18,23,24,39,40] how would you write a function to generate random numbers that can add up to a 100? I need to know how many random numbers can add up to a 100.
I want to make an array with a range of number from 1-9 only. So if the user entered more than or less than the number indicated it will be error and ask the user to reinput the data. So far my code can be used to do so that if the user enter the number one by one... But if the user entered all the number in one shot the reentered value will be prompt to the back automatically for some reason...Let say 10,2,3,4 which was suppose to be 1,2,3,4 became 2,3,4,1 instead... here is the code:
#include<stdio.h> void main() { int num[4][4]; int row,col,x,y; for(row=0;row<4;row++)
How do i make the srand() function make new numbers every time i call it? Now it seems like it repeats its result over an over again.
Below is a program that should generate random numbers for 3 dices and print these out. But it prints out the same nr over and over.
Code: #include <stdio.h> #define MAX 100 int filler(int dice1[MAX], int dice2[MAX], int dice3[MAX]) { int throws, nr; printf("Define the number of throws"); scanf("%d", &kast);
I want to make a program to print the product of even numbers between 1 and 30 and sum of odd numbers between 1 and 30. But the answer of product is negative. The photo shows the output of the code.
#include <stdio.h> #include <conio.h> void main () { int i, even_product=1, odd_sum=0; for(i=1;i<=30;i++) // For loop starts here!
4.1 Write a program that will count from 1 to 12 and print the count, and its square, for each count.
4.2 Write a program that counts from 1 to 12 and prints the count and its inversion to 5 decimal places for each count. This will require a floating point number.
4.3 Write a program that will count from 1 to 100 and print only those values between 32 and 39, one to a line. Use the incrementing operator for this program.