[ create a new paste ] login | about

Link: http://codepad.org/e8pziVHm    [ raw code | output | fork ]

C, pasted on Sep 29:
#include <stdio.h>


int main(void)      {

    int count,sum,square;           
    int upto=10;                 
    sum = 0;
    count = 0;                
    square = 0;                 

    while (++count < upto)   {   
        square = count * count;
        printf("square of %d is %d",count,square);     
        sum =square + sum;
        printf(" running total is %d\n", sum);}

    printf("overall total of squares of integers 1 thru 10 is %d\n", sum);           

    return 0;
}
    


Output:
1
2
3
4
5
6
7
8
9
10
square of 1 is 1 running total is 1
square of 2 is 4 running total is 5
square of 3 is 9 running total is 14
square of 4 is 16 running total is 30
square of 5 is 25 running total is 55
square of 6 is 36 running total is 91
square of 7 is 49 running total is 140
square of 8 is 64 running total is 204
square of 9 is 81 running total is 285
overall total of squares of integers 1 thru 10 is 285


Create a new paste based on this one


Comments: