Question
Asked by:
ipxt
ipxt
Rating : No Rating
Questions Asked: 31
Tutorials Posted: 0
 

$30.00 C Programming Assignment For Loops Fo

Q:
C Programming Assignment
For Loops

For each of the programs assigned below, submit the following:
• Hard copy of the source code.

Observe the usual guidelines regarding the initial comment section, indenting, and so on. In addition,
• Place function prototypes before function main. Place function definitions following main.
• Before each function use comments to explain what the function does.
• In if-else statements, indent statements to be executed for if or else condition three spaces. Align else or else if with corresponding if.
• Indent statements within loops. Indent nested loops.
• Do not use global variables.

Programs:
1. Seed the random number generator with the time of day. In a for loop generate 10 random numbers between 1 and 50, one number on each pass through the loop. Print the numbers as they are generated. Also in the same for loop, find the minimum, maximum, and sum of the values. Print the minimum, maximum, and average after exiting from the loop. This program may be done entirely in function main.


2. Write a program to find the approximation of ln(2) using the following formula for m+1 terms:
where n = 0, 1, 2, … m

Prompt the user to enter the number of terms (between 10 and 50 inclusive) to be used in the approximation. While calculating each term in the sum, print a table. Each line of the table should include the term (iteration) number, the value of the term added to the sum at that iteration accurate to 5 decimal digits, and the value of the sum at that iteration also printed with 5 decimal digits. Use doubles for the term and sum approximation values. At the end of the program print the final value of the sum and the actual value of ln(2) from the C library using 5 decimal digits. This entire program may be written in function main.


3. Using nested for loops, write functions to create two patterns shown below. In function main, prompt the user for the height (number of rows) and width (number of characters per line) for patterns to be created. You may use any number for height and width, just as long as the basic pattern is preserved. Then call the functions to print the patterns. (Note: The first function requires only the height. Neither function will return a value---will merely print.)

Pattern 1:

*******
******
*****
****
***
**
*

Pattern 2
= = = = = = =
* *
* *
* *
* *
* *
= = = = = = =
Hint: Use if – else if –else within nested loop structure to tell function what to print on each line.
 
Attachments:
C Programming Assignment.doc (27K)


   
   
   
   
 
Available Tutorials to this Question
Posted by:
afrenchguy
afrenchguy
Rating : No Rating
Questions Asked: 0
Tutorials Posted: 1, earned $0.00
 

$10.00 Loops tutorial

  • This tutorial hasn't been purchased yet.
  • Posted on Mar. 08, 2009 at 06:53:28AM
A:
Preview: ... first assignment :<br>#include <stdio.h><br>#include <time.h><br><br>int main(void) {<br> int i, max, min, sum;<br> sum = 0;<br> ...

The full tutorial is about 165 words long plus attachments.

Attachments:
cassign1.c (0K) (Preview)
cassign2.c (0K) (Preview)
cassign3.c (1K) (Preview)
Posted by:
rainman
rainman
Rating (40): A+
Questions Asked: 2
Tutorials Posted: 174, earned $906.64
 

$10.00 Tutorials & C Program Source Code For Problems. Does Everything Asked. Compiled, Tested, Commented, Works!

  • This tutorial hasn't been purchased yet.
  • Posted on Mar. 08, 2009 at 07:02:51AM
A:
Preview: ... ttern1(int height)<br>{<br> int i, j;<br><br> printf("\\\\nPATTERN 1: \\\\n\\\\n");<br><br> //for loop for height<br> for (i = 0; i < height; i++)<br> {<br> //The pattern prints as many asterisks as there are lines left<br> for (j = i; j < height; j++)<br> {<br> printf("*");<br> }<br> printf("\\\\n"); //print a new line<br> }<br>}<br> ...

The full tutorial is about 198 words long plus attachments.

Attachments:
one.c (1K) (Preview)
two.c (1K) (Preview)
three.c (1K) (Preview)
three prev.JPG (16K) (Preview)
   
Join Now or Log In
Get Tutoring
Get Paid
Academic Honesty