Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [C] Simple adding program.  (Read 730 times)

0 Members and 1 Guest are viewing this topic.

gm112

[C] Simple adding program.
« on: August 12, 2006, 10:03:40 pm »
Meh.. I decided to cook up a simple user-based input example. I've decided to do a simple addition program, since it is a good way for people thats learning C to learn how to do user input stuff.

All code commented.
Code: [Select]
#include <stdio.h> //Include our files.

int main() //Startup our main program.
{
    int a,b,answer; //Set a,b,and answer as our integers
 printf ("Enter a number:\n"); //Print Enter a number. \n makes a new line

 scanf("%d",&a); //Get user input, %d will read our set integer.
 scanf("%d",&b); //same as abovee
   
     answer = a+b; //Declare what answer is, then add a+b
   
      printf("%d + %d = %d\n",a,b,answer); //print our problem then, print the answer and create a new line.

    scanf("%d"); //Wait for user input to end.
  return 0; //End everything! =P
}

edit: forgot to tell...

// is a comment
/*
 This is a block
*/

printf prints the user defined text
scanf read's the defined integer.
---------------------
%'s now, this was confusing at first, really this is freaking convinent!
%d decimal integer.
%c single character
%i integer
%e, %f, and %g all are float values
%o octal number
%s cmon! A string =D
%x hexidecimal number
%p I smell pointers =P
%n integer that is equal to the number of characters read, so far...
%u unsinged integer
%[] a set of characters


------------------------------------
\n Makes a new line

------------------------------------

There ya go!
« Last Edit: March 01, 2007, 01:33:20 am by 4Sword »
Logged
Re: [C] Simple adding program.
« Reply #1 on: August 13, 2006, 03:27:16 am »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
Interesting. Though, VERY simple :P
Logged
the a o d c
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.038 seconds with 38 queries.