05/21/2014

Programs 03

Directions: These programs are all modifications of the program presented in the Overview page and discussed on the Program page. Program main should define some variables. Then we will have
while (condition)
  Statement
This is called a while-loop. The word "loop" because execution loops back to do another repetition. The word "while" because we will soon see that there are other keywords that cause loops. The Statement can be simple or compound. The statement may contain assignments or printf calls or both. In addition you may want a statement after the statement that loops.

IMPORTANT: Pay attention to program names. If you write and save a file with the name S1.c instead of the name s1.c, it is WRONG. The program that I use expects the name I give you. You do not have to do all programs

Sum Problems

  1. Write a C program with file name s1.c. The content of the file should be the program discussed in this week (Week 03).
  2. Write a C program with file name s2.c that finds and prints the sum of the first 1000 positive numbers (1+2+3+...+1000). Your program should print just one value: the value of the final sum.
  3. Write a C program with file name s3.c that adds consecutive positive integers starting with 1: 1+2+3+... until the sum goes over 5000. The program should print the number that makes the sum go over 5000. Again just one number should be printed, the value that makes the sum larger than 5000.
  4. Write a C program with file name s4.c that finds and prints the sum of the odd numbers less than 200 (1+3+5+7+...+197+199). Just one print!
  5. Write a C program with file name s5.c that finds the sum of the first 90 consecutive odd numbers. The only print should be of the value of the final sum.
  6. Write a C program with file name s6.c that finds and prints the number of consecutive odd numbers that must added in order that their sum equals 14400. Note don't print the sum and don't print the odd number. Just one print.

Pattern Problems

  1. Write a C program with file name pat1.c. that prints
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
    Requirements:
  2. Write a C program with file name pat2.c. that prints
    12345678910
    
    Requirements:
  3. Write a C program with file name pat3.c. that prints
    10
    9
    8
    7
    6
    5
    4
    3
    2
    1
    
    Requirements: