| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
C project
i have taken C++ in the past but to me down grading is different. i do not really understand the pow and square root functions itself.. can someone please help me to understand and how to use them like examples:
Project 3 - 15 points This project deals with range-based loops where we know the exact number of times a loop will iterate (perform the associated block of code). Given: int x, lower, upper; double square, squareroot; Have the user enter a lower bound and an upper bound for a range of integers. You will then construct a for loop to process the range of values from the lower bound to the upper bound, inclusive, incrementing by one each time. Each time through the loop, using the pow and sqrt functions, calculate the square and square root of each value and store the result in the appropriate variable. Display your results. Your output should resemble: Enter a lower bound: 3 Enter an upper bound: 9 For the value 3 the square is 9.00 and the square root is 1.73 For the value 4 the square is 16.00 and the square root is 2.00 For the value 5 the square is 25.00 and the square root is 2.24 For the value 6 the square is 36.00 and the square root is 2.45 For the value 7 the square is 49.00 and the square root is 2.65 For the value 8 the square is 64.00 and the square root is 2.83 For the value 9 the square is 81.00 and the square root is 3.00 NOTE: The user entered 3 and 9 in the above test! This project should be called p3.c and submitted using: $ submit jojo p3.c __________________________________________________ __ #include <stdio.h> #include <stdlib.h> #include <math.h> int main () { int x, lower, upper, i, num; /* assigning integer values*/ double square, squareroot; /* assigning double float values*/ printf("Enter two values, a lower and an upper bound please: "); scanf("%d", lower); scanf("%d", upper); for(i=lower;i<upper;i++){ printf("x = x*x"); printf("x = x*x*x"); } printf("%d,%d,%d"); } Thanks for your help -D |
|
#2
|
|||
|
|||
|
got that complete, sorry about that fluke...
project 4: Project 4 - 15 points This project deals with sentinel-based loops where we do not know the exact number of times a loop will iterate (perform the associated block of code). Use the variables given below to solve the problem. You should need no other variables to complete this project. Given: int num, sum, valid, invalid; float avg; Using your knowledge of C and using num as your loop control variable, write a while loop to read positive integers from the user until the user enters the integer value -1. This is the sentinel value indicating that the user has finished entering data. As you are reading in the values you should be keeping track of how many positive values have been read so far (valid) simultaneously keeping a running total (sum). The user must use -1 to terminate the program, but may enter a value less than -1. You should not include these values in the running total or in the number of positive values read from the user. Instead you should increment the count of invalid numbers entered by the user. Zero should be considered a positive value for the extent of this project. You will report to the user the number of positive values they entered, the number of invalid values, the sum and average of the positive values. The average should should be displayed as a floating point value. This project should be called p4.c and submitted using: $ submit jojo p4.c |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > C project |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|