Showing posts with label adding integers. Show all posts
Showing posts with label adding integers. Show all posts

C Language | Addition part 2

Wednesday, 5 December 2012


Last time, I showed you how to create a simple addition program using C language. Now, we will still be adding numbers but I put something new in it. Yes, we will still add integers/numbers but it is now in the users decision how many integers he will add.

We will still use int as our data identifier because we are still inputting integers. The new command we're going to put into the code is the for loop statement. This statement will control how many inputs a user want. From the name itself, loop, it means infinity. For loop is a repetitive statement, the program will not stop/end until the argument inside the loop is met. This statement is useful when you have to make repetitive programs because this will excuse you from doing the same code again and again.

The program you see below is an example of adding numbers but inputs can be manipulated by the user. Check out the codes below.


   1:   
   2:   
   3:   
   4:  #include <stdio.h>
   5:  #include <conio.h>
   6:   
   7:  int main()
   8:  {
   9:      int a, b = 0, c = 1, sum = 0;
  10:   
  11:      printf("How many numbers you want to add?: ");
  12:      scanf("%d", &a);
Related Posts Plugin for WordPress, Blogger...