Advertisement
TheWhiteFang

Tutorial 1 part A

Oct 26th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. //http://pastebin.com/u/TheWhiteFang
  2. // Tut01.cpp : Defines the entry point for the console application.
  3. //
  4.  
  5. #include <stdio.h>
  6.  
  7. int main() {
  8.    
  9.     int x = 2;
  10.     switch(x)
  11.     {
  12.                 case 2:
  13.                      printf("Two\n");
  14.                      break; //no break
  15.                 case 3:
  16.                      printf("Three\n");
  17.                      break;
  18. }
  19.  
  20.  
  21.  
  22.     return 0;
  23. }
  24. -----------------------------------------------------------------------------------------------------------------------------------
  25. // Tut01.cpp : Defines the entry point for the console application.
  26. //
  27.  
  28. #include <stdio.h>
  29.  
  30. int main() {
  31.    
  32.     int x = 4;
  33.         if ( x == 6 ) //==
  34.         {
  35.              printf("x equals 6\n");
  36.         }
  37.  
  38.     return 0;
  39. }
  40. -----------------------------------------------------------------------------------------------------------------------------------
  41. // Tut01.cpp : Defines the entry point for the console application.
  42. //
  43.  
  44. #include <stdio.h>
  45.  
  46. int main() {
  47.    
  48. for (int i=100; i>=0;i-=3) // i>=0
  49.         {
  50.             printf("i equals %d\n", i);
  51.         }
  52.  
  53.     return 0;
  54. }
  55. -----------------------------------------------------------------------------------------------------------------------------------
  56. // Tut01.cpp : Defines the entry point for the console application.
  57. //
  58.  
  59. #include <stdio.h>
  60.  
  61. int main() {
  62.    
  63.     double halfval=1.0/2.0; //1.0 and 2.0
  64.     printf( "Halfval %g\n",halfval); //%g or %lf
  65.  
  66.     return 0;
  67. }
  68. -----------------------------------------------------------------------------------------------------------------------------------
  69. // Tut01.cpp : Defines the entry point for the console application.
  70. //
  71.  
  72. #include <stdio.h>
  73.  
  74. int main() {
  75.    
  76.        
  77.         char st1[] = "abc";
  78.         char st2[] = "abc";
  79.  
  80.             if ( st1 == st2 ) //address compared not chararray
  81.             {
  82.                 printf("Yes\n");
  83.             }
  84.             else
  85.             {
  86.                 printf("No\n");
  87.             }
  88.     return 0;
  89. }
  90. -----
  91.  
  92. int a, intArray[5];
  93. for (a=0 ; a <= 10 ; a++)
  94. intArray[a] = a * 2;
  95. int x;
  96. char st[31];
  97. printf("Enter an integer: ");
  98. scanf(%d, &x); //unflushed somth
  99. printf("Enter a line of text: ");
  100. fgets(st, 31, stdin);
  101.  
  102. -----
  103.  
  104. //skipped declar int test
  105.  
  106. ----
  107.  
  108. 010; //octal casting
  109.  
  110. ----
  111. -5 10 5 9 6 99 1000 85 5000 -50 -100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement