SHARE
TWEET

Untitled

a guest Nov 19th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7.  
  8. /*
  9.     - Learning basics of "printf", and some variables.
  10. */
  11.  
  12.     char characterName[] = "Tom";
  13.     int characterAge = 58;
  14.  
  15.     printf("There once was a man named %s.\n", characterName);
  16.     printf("He was %d years old.\n", characterAge);
  17.     printf("He really liked his name %s.\n", characterName);
  18.  
  19.     characterAge = 34;
  20.  
  21.     printf("But he wanted to be younger.\n");
  22.     printf("His dream was to be %d years old.\n", characterAge);
  23.  
  24. /*
  25.     - Data Types
  26. */
  27.  
  28.     int age = 40;
  29.     double gpa = 3.6;
  30.     char grade = 'M';
  31.     char phrase[] = "Giraffe Academy";
  32.  
  33. /*
  34.     - Printf
  35.  
  36.     - %d - Normal number (int)
  37.     - %f / %lf - Decimal Number (double, float)
  38.     - %s - Normal text (char ..[])
  39.     - %c - Single character (char)
  40. */
  41.  
  42.     int favNum = 14;
  43.     char myText[] = "number";
  44.     printf("\nMy favorite %s is %d\n", myText, favNum);
  45.  
  46. /*
  47.     - Numbers
  48.  
  49.     - Pow
  50.     - Sqrt
  51.     - Ceil
  52.     - Floor
  53. */
  54.  
  55.     printf("\nHow much upper-bound of 25.153?\n");
  56.     printf("The answer is: %f\n", ceil(25.153) );
  57.  
  58. /*
  59.     - Comments
  60. */
  61.  
  62.     printf("\nComments are fun!\n");
  63.  
  64. /*
  65.     - Constants
  66.  
  67.     - Can't be modified, if you use "const"!
  68. */
  69.  
  70.     const int FAV_NUM = 5;
  71.     printf("\nMy favorite number is: %d\n", FAV_NUM);
  72.  
  73. /*
  74.     - Getting User Input
  75.  
  76.     - Scanf - Allowing user to answer questions, in
  77.      your program.
  78.  
  79.     - scanf - When you use it with string it's only going to grab the first characters what you typed.
  80.     - fgets -
  81.     - stdin - Storing the input what you typed, and it can be remember multiple words.
  82. */
  83.  
  84.     int yourAge;
  85.     printf("\nEnter your age: \n");
  86.     scanf("%d", &yourAge);
  87.     printf("You are %d years old!\n", yourAge);
  88.  
  89.     double yourGpa;
  90.     printf("\nEnter your gpa: \n");
  91.     scanf("%lf", &yourGpa);
  92.     printf("Your gpa is %f!\n", yourGpa);
  93.  
  94.     char yourGrade;
  95.     printf("\nEnter your grade: \n");
  96.     scanf("%c", &yourGrade);
  97.     printf("Your grade is %c !\n", yourGrade);
  98.  
  99.     char yourName[20];
  100.     printf("\nEnter your name: \n");
  101.     fgets(yourName, 20, stdin);
  102.     printf("Your name is %s!\n", yourName);
  103.  
  104.     return 0;
  105. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top