Tag Archives: New line in C

C Programming Tutorial – 5 – Define an Array + replace a character in an array :

Published by:

Note:

  • //Define array:
    char name[15]= “Sajjad Baghaee”;
  • // replacing a character in an array : 
    name[2]= ‘C’;
  • Array start by 0 so S=0 a=1  j=2  j=3  a =4  d=5 =6  B=7  a=8  g=9  h=10  a=11  e=12  e=13

Code:
—————————

#include <stdio.h>
#include <stdlib.h>

int main()
{

char name[15]= “Sajjad Baghaee”;
printf(“This is %s \n”, name);
name[2]= ‘C’;                  // replacing the 1st character “j” in array “Sajjad Baghaee”  with “C”
name[3]=’c’;                   // replacing the 2nd character “j” in array “Sajjad Baghaee”  with “c”
printf(“This is %s\n”,name);

return 0;

}

C Programming Tutorial – 3 – what can we do with “printf()” ? :

Published by:

Code:
—————————

#include <stdio.h>
#include <stdlib.h>

int main()
{

  • // Print “Hello world!” on the screen + goes to new line
    printf(“Hello world!\n”);

 

  • // Print “Hi Sajjad” on the screen + insert a tab space
    printf(“Hi Sajjad\t”);

 

  •  // Print “This is a tab test” on the screen + goes to new line + make a alarm sound
    printf(“This is a tab test\n\a”);

 

  • // Conversion string use %s to replace a string
    printf(“%s is an intelligent boy and %s\n” , “SAJJAD”,”programmer”);

 

  • // Conversion integer use %d to replace a integer number
    printf(“I ate %d eggs last morning\n”,2);

 

  •  // Conversion decimal use %f to replace a decimal number
    printf(“my weight is %f\n”, 80.467896212);

 

  •  // Conversion decimal use %.4f to replace a decimal number with 4 decimal number
    printf(“my weight is %.4f\n”, 80.467896212);

 

  • // Conversion decimal use %.2f to replace a decimal number with 2 decimal number
    printf(“my weight is %.2f\n”, 80.467896212);

return 0;

}