Posts

Showing posts from January, 2024

Simple and basic C program code

Image
Convert given value in Meter to centimeter. #include <stdio.h> int main (void) { float length; printf("Enter Value for length in meter : "); scanf("%f",&length); printf("%.2fm equal to %.2fcm\n", length, length*100); return 0; }   Calculate the volume of a cylinder. PI * r2 h #include <stdio.h> #define PI 3.1412 int main (void) { float radius, height, volume; /* Get value for radius */ printf("Enter the radius : "); scanf("%f",&radius); /* Get the value for height in Cylinder */ printf("Enter the height : "); scanf("%f", &height); /* Calculate the Volume */ volume = PI * radius * radius * height; printf("Volume of a cylinder %.2f\n", volume); return 0; }  Calculate average marks of 4 subjects which, entered separately.    #include <stdio.h> int main (void) { int sub1, sub2, sub3, sub4; double average; /* Get values */ printf("Ent...

Programming Errors in C

Image
   ERRORs    Errors (bugs) cause programs to malfunction, even for experienced developers. Debugging is the process of identifying and fixing these errors. This shortens the original text while retaining the key points: errors cause problems, developers make them, and debugging fixes them. These errors are detected either during the time of compilation or execution. Thus, the errors must be removed from the program for the successful execution of the program. There are mainly five types of errors exist in C programming: Syntax error Run-time error Linker error Logical error Semantic error Very important thing is understanding errors in C programming Identify the syntactic errors in the following program. #include <stdio.h> int main (Void) (      INT sum;      /* COMPUTE RESULT      sum = 25 + 37 – 19      /* DISPLAY RESULTS //      printf("The answer is %i\n" sum);      re...

Format Modifiers (Format Specifiers)

Image
Format specifiers are the secret codes in C that control how data is displayed and input. They're like instructions for the computer, telling it how to format numbers, characters, and other data types the way we want when using functions like printf() and scanf() . Mastering these codes is crucial for any C programmer who wants their programs to work flawlessly. List of Format Specifiers in C Format Specifier        Description %c                 For character type. %d                                 For signed integer type. %e or %E            For scientific notation of floats. %f                  For float type. %g or %G           For float type with the current precision. %i                     ...

Variables and Data types

Image
    Keywords / Reserve Words     Keywords are predefined, reserved words used in programming that have special meanings to the compiler. As C is a case sensitive language, all keywords must be written in lowercase. There are only 32 keywords in the C language. auto    break      case      char      const      continue      default  do      double    else      enum      extern    float         for      goto    if         int       long      register  return      short signed    sizeof      static      struct      switch typedef union unsigned      void volatile while    Identifiers  ...

scan() Function

Image
scanf("format string",argument_list);   The scanf() function is used for input. It reads the input data from the console. The first ("%i") specifies what type of data type is expected (char, int, or float).  The second argument (&number) specifies the variable into which the typed response will be placed. In this case the response will be placed into the memory location associated with the variable number. In C programming, when you use the & (ampersand) character, it is known as the "address-of" operator. It provides the memory address where a variable is stored. Understanding this is crucial for scenarios where you want to manipulate or interact with the actual memory location of a variable.  In programming languages like C, input from users via keyboard input is commonly achieved using the `scanf()` method. However, there are scenarios where formatted data needs to be read from one string into another rather than directly from the keyboard. This...

printf() Function

Image
printf(“Programming is fun.\n” ); In C programming, printf() is a standard library function used for printing formatted output to the console or other output streams. It stands for "print formatted" and is part of the <stdio.h> header file. The parameter or argument to be passed to the printf routine is the string of characters “Programming is fun.\n” \n Any characters to be printed after the newline character then appear on the next line of the display. Using printf(); 1) #include<stdio.h> int main() { printf("In C, lowercase letters are significant.\n"); printf("main is where program execution begins.\n");           printf("Opening and closing braces enclose program statements in a routine.\n");           printf("All program statements must be terminated by a semicolon.\n"); return 0; } Output👇 2) #include <stdio.h>     int main(){     printf("*\n"); printf("**\n"); ...