programming in C code example

Example 1: c

#include <stdio.h>

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

Example 2: c language tutorial

#include <stdio.h>

int main() {
   /* my first program in C */
   printf("Hello, World! \n");
   
   return 0;
}

Example 3: functions in c programming

#include <stdio.h>
/* function return type is void and it doesn't have parameters*/
void introduction()
{
    printf("Hi\n");
    printf("My name is Chaitanya\n");
    printf("How are you?");
    /* There is no return statement inside this function, since its
     * return type is void
     */
}

int main()
{
     /*calling function*/
     introduction();
     return 0;
}

Example 4: functions in c programming

#include <stdio.h>
int addition(int num1, int num2)
{
     int sum;
     /* Arguments are used here*/
     sum = num1+num2;

     /* Function return type is integer so we are returning
      * an integer value, the sum of the passed numbers.
      */
     return sum;
}

int main()
{
     int var1, var2;
     printf("Enter number 1: ");
     scanf("%d",&var1);
     printf("Enter number 2: ");
     scanf("%d",&var2);

     /* Calling the function here, the function return type
      * is integer so we need an integer variable to hold the
      * returned value of this function.
      */
     int res = addition(var1, var2);
     printf ("Output: %d", res);

     return 0;
}

Example 5: c programming language

// this is a single-line comment
/*
this is a multi-line comment!
*/

#include <stdio.h> // this library is included for i/o
#include <stdlib.h> // this library is included for some handy functions

// This function will be ran when the program executes
int main() {
 
  printf("Hello, world!\n"); // this prints "Hello, world!" [line break]
  
  char* myString = "An awesome string!"; // declare string variable!
  printf("%s\n", myString); // print myString where %s is
  
  int myInt = 10;
  printf("%d\n", myInt); // print myInt where %d is
  
  double myDouble = 5.2; // declare double (decimal) variable!
  printf("%f\n", myDouble); // print myDouble where %f is
  
  return 0; // < exit out of the program
}

Example 6: c programming language

Do not want to be rude but I learnt this language and found out it has no class.
Prefer languages with class like C++, C#, Java, Python, etc.
Be classy.

Tags: