C instructions

 Types of Instruction

  • Type Declaration Instruction
    • int
      • int age, number, page;
    • float
      • float temperature, weight;
    • char
      • char boolen;
      • char name[20];
      • char address[10];
  • Arithmetic Instruction
    • int i, length, breadth, area;
    • i=i+1;
    • area=length*breadth;
    • Exponential case, 
      #include<stdio.h>
      int main(){
      float a;
      a=pow(3.0/2.0);
      printf("%f",a);
      return 0;
      }
  • Control Instruction
    • Sequence Control Instruction
      • Sequence control instructions are those that allow statements to be executed in sequence, from top to bottom, without any conditions or loops. Essentially, it's the default behavior of a program.
      • #include <stdio.h>

        int main() {
            printf("Hello, ");
            printf("world!\n");
            return 0;
        }


    • Selection or Decision Control Instruction
      • Selection or decision control instructions are used to execute different blocks of code based on certain conditions. The if-else statement is a common example of this type of control instruction.
      • #include <stdio.h>

        int main() {
            int x = 10;

            if (x > 5) {
                printf("x is greater than 5\n");
            } else {
                printf("x is not greater than 5\n");
            }

            return 0;
        }

    • Repetition or Loop Control Instruction
      • Repetition or loop control instructions are used to execute a block of code repeatedly based on certain conditions. Examples include for, while, and do-while loops.
      • #include <stdio.h>

        int main() {
            for (int i = 0; i < 5; i++) {
                printf("%d ", i);
            }
            printf("\n");

            return 0;
        }

    • Case Control Instruction
      #include <stdio.h>

      int main() {
          int a = 10, b = 20;

          // if-else statement
          if (a > b) {
              printf("a is greater than b\n");
          } else {
              printf("a is not greater than b\n");
          }

          // for loop
          printf("For loop example:\n");
          for (int i = 1; i <= 5; i++) {
              printf("%d ", i);
          }
          printf("\n");

          // while loop
          printf("While loop example:\n");
          int count = 1;
          while (count <= 5) {
              printf("%d ", count);
              count++;
          }
          printf("\n");

          // do-while loop
          printf("Do-while loop example:\n");
          count = 1;
          do {
              printf("%d ", count);
              count++;
          } while (count <= 5);
          printf("\n");

          // switch statement
          printf("Switch statement example:\n");
          int day = 3;
          switch (day) {
              case 1:
                  printf("Sunday\n");
                  break;
              case 2:
                  printf("Monday\n");
                  break;
              case 3:
                  printf("Tuesday\n");
                  break;
              default:
                  printf("Other day\n");
          }

          // break statement
          printf("Break statement example:\n");
          for (int i = 1; i <= 10; i++) {
              if (i == 5) {
                  break;  // Exit the loop when i is 5
              }
              printf("%d ", i);
          }
          printf("\n");

          // continue statement
          printf("Continue statement example:\n");
          for (int i = 1; i <= 10; i++) {
              if (i == 5) {
                  continue;  // Skip the rest of the loop body when i is 5
              }
              printf("%d ", i);
          }
          printf("\n");

          // goto statement
          printf("Goto statement example:\n");
          goto myLabel;  // Jump to myLabel
          printf("This will be skipped.\n");
          myLabel:
          printf("Jumped to myLabel using goto.\n");

          return 0;
      }



0 Comments had been done yet:

Post a Comment