Darren Daly / Mbed 2 deprecated mbed_blinkyembeddedsystemslab2functions

Dependencies:   mbed

Committer:
darrendaly
Date:
Mon May 10 16:09:34 2021 +0000
Revision:
0:20db2fce0d5c
lab 2 pt 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
darrendaly 0:20db2fce0d5c 1 // Program to calculate the sum of first n natural numbers
darrendaly 0:20db2fce0d5c 2 // Positive integers 1,2,3...n are known as natural numbers
darrendaly 0:20db2fce0d5c 3
darrendaly 0:20db2fce0d5c 4 #include <stdio.h>
darrendaly 0:20db2fce0d5c 5 int main()
darrendaly 0:20db2fce0d5c 6 {
darrendaly 0:20db2fce0d5c 7 int num, count, sum = 0;
darrendaly 0:20db2fce0d5c 8
darrendaly 0:20db2fce0d5c 9 printf("Enter a positive integer: ");
darrendaly 0:20db2fce0d5c 10 scanf("%d", &num);
darrendaly 0:20db2fce0d5c 11
darrendaly 0:20db2fce0d5c 12 // for loop terminates when num is less than count
darrendaly 0:20db2fce0d5c 13 for(count = 1; count <= num; ++count)
darrendaly 0:20db2fce0d5c 14 {
darrendaly 0:20db2fce0d5c 15 sum += count;
darrendaly 0:20db2fce0d5c 16 }
darrendaly 0:20db2fce0d5c 17
darrendaly 0:20db2fce0d5c 18 printf("Sum = %d", sum);
darrendaly 0:20db2fce0d5c 19
darrendaly 0:20db2fce0d5c 20 return 0;
darrendaly 0:20db2fce0d5c 21
darrendaly 0:20db2fce0d5c 22