Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main()
- {
- /*
- - Learning basics of "printf", and some variables.
- */
- char characterName[] = "Tom";
- int characterAge = 58;
- printf("There once was a man named %s.\n", characterName);
- printf("He was %d years old.\n", characterAge);
- printf("He really liked his name %s.\n", characterName);
- characterAge = 34;
- printf("But he wanted to be younger.\n");
- printf("His dream was to be %d years old.\n", characterAge);
- /*
- - Data Types
- */
- int age = 40;
- double gpa = 3.6;
- char grade = 'M';
- char phrase[] = "Giraffe Academy";
- /*
- - Printf
- - %d - Normal number (int)
- - %f / %lf - Decimal Number (double, float)
- - %s - Normal text (char ..[])
- - %c - Single character (char)
- */
- int favNum = 14;
- char myText[] = "number";
- printf("\nMy favorite %s is %d\n", myText, favNum);
- /*
- - Numbers
- - Pow
- - Sqrt
- - Ceil
- - Floor
- */
- printf("\nHow much upper-bound of 25.153?\n");
- printf("The answer is: %f\n", ceil(25.153) );
- /*
- - Comments
- */
- printf("\nComments are fun!\n");
- /*
- - Constants
- - Can't be modified, if you use "const"!
- */
- const int FAV_NUM = 5;
- printf("\nMy favorite number is: %d\n", FAV_NUM);
- /*
- - Getting User Input
- - Scanf - Allowing user to answer questions, in
- your program.
- - scanf - When you use it with string it's only going to grab the first characters what you typed.
- - fgets -
- - stdin - Storing the input what you typed, and it can be remember multiple words.
- */
- int yourAge;
- printf("\nEnter your age: \n");
- scanf("%d", &yourAge);
- printf("You are %d years old!\n", yourAge);
- double yourGpa;
- printf("\nEnter your gpa: \n");
- scanf("%lf", &yourGpa);
- printf("Your gpa is %f!\n", yourGpa);
- char yourGrade;
- printf("\nEnter your grade: \n");
- scanf("%c", &yourGrade);
- printf("Your grade is %c !\n", yourGrade);
- char yourName[20];
- printf("\nEnter your name: \n");
- fgets(yourName, 20, stdin);
- printf("Your name is %s!\n", yourName);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement