chp4ex3 - printf"Sum how many numbers"...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 /* * chp4ex3.c * This program asks for a number which * counts that amount of consecutive odd integers * and finds the sum. */ //include default material #include <stdio.h> #include "genlib.h" #include "simpio.h" int main() { //amount of odd numbers int AmountOfOddNumbers = 0 //used to hold the temporary value of each number in the loop int FindOddNumber = 0 int SumOfOddNumbers = 0 printf("This program calculates the sum of the first N odd numbers.\n") //prompt the user for the amount of odd integers
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printf("Sum how many numbers: ") AmountOfOddNumbers = GetInteger() //loop to find each odd number and add it to SumOfOddNumbers for(int x=0 //find the odd number FindOddNumber = x*2+1 //add the odd number to the sum SumOfOddNumbers += FindOddNumber } //print the sum of the odd integers printf("The sum of the first %d odd integers is %d.\n", AmountOfOddNumbers, SumOfOddNumbers) } Sheet1 Page 2 x<AmountOfOddNumbers x++){...
View Full Document

This note was uploaded on 04/18/2008 for the course CS 120 taught by Professor Towell during the Spring '08 term at Abilene Christian University.

Page1 / 2

chp4ex3 - printf"Sum how many numbers"...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online