Professional Documents
Culture Documents
VARIABLE DECLARATION
#include <stdio.h>
main()
{
/* There's no ouput if your will try to compile and run this program since you are just declaring a
variable*/
char Middle_Intial;
int Age;
float Weight;
double Speed;
}
CHAR TO INT FLOAT DOUBLE
#include <stdio.h>
main()
{
char ch;
int i;
float f;
double d;
ch = 'A';
i = ch;
f = ch;
d = ch;
printf("%d\n", i);
printf("%f\n", f);
printf("%lf\n", d);
}
DOUBLE TO FLOAT
#include <stdio.h>
main()
{
float f;
double d;
d = -875.39391234;
f = d;
printf("%f\n", f);
}
2
main()
{
char ch1, ch2;
float f;
double d;
f = 65.123;
ch1 = f;
d = 90.908765;
ch2 = d;
printf("%c\n", ch1);
printf("%c\n", ch2);
}
FLOAT AND DOUBLE TO INT
#include <stdio.h>
main()
{
int i, ii ;
float f;
double d;
f = 135.66;
i = f;
d = -49.991234;
ii = d;
printf("%d\n", i);
printf("%d\n", ii);
}
INT TO CHAR
#include <stdio.h>
main()
{
char ch1, ch2;
int i, ii;
i = 65;
ch1 = i;
3
ii = 299;
ch2 = ii; // Note that a char can only store up to 255, thus this behavior is undefined
printf("%c\n", ch1);
printf("%c\n", ch2);
}
main()
{
/* The size of the data types will depende of the compiler being used*/
printf("Size of char = %d\n", sizeof(char)); //sizeof is a keyword or C Programming
printf("Size of int = %d\n", sizeof(int)); //sizeof is a keyword or C Programming
printf("Size of float = %d\n", sizeof(float)); //sizeof is a keyword or C Programming
printf("Size of double = %d", sizeof(double)); //sizeof is a keyword or C Programming
}
CONSTANT
#include <stdio.h>
#define pi 3.14159 //Syntax is <#define> <name> <replacement text or simply the constant value>
#define M_I 'M' //Syntax is <#define> <name> <replacement text or simply the constant value>
#define First_Name "Kyle" //Syntax is <#define> <name> <replacement text or simply the constant value>
#define Age 20 //Syntax is <#define> <name> <replacement text or simply the constant value>
main()
{
const int xx = 23; // It is another way for declaring Constant - Syntax is <const> <data type> <variable> =
<value>;
float p = pi;
char x = M_I;
char* y = First_Name; // The * in char* is a pointer,and in a function parameter list, char[] is a synonym
for char*
int z = Age;
printf("%f\n", p); // printf is a library command for output data under #include <stdio.h>
printf("%c\n", x); // printf is a library command for output data under #include <stdio.h>
printf("%s\n", y); // printf is a library command for output data under #include <stdio.h>
printf("%d\n", z); // printf is a library command for output data under #include <stdio.h>
printf("%d\n", xx); // printf is a library command for output data under #include <stdio.h>
}
ARITHMETIC MDAS
#include <stdio.h>
main()
{
int a, b, c, d; // Variable Declaration
4
a = 3; b = 4; c = 5, d =6; // Initialization
result = (a + b)* c / d; // Arithmitic Operations using MDAS
}
ARITHMETIC DECREMENT INCREMENT
#include <stdio.h>
main()
{
int a, b, c, d, e , f, g,h;
a = 5 + 10;
b = 22 - 15;
c = 2 * 3;
d = 20 / 8;
e = 20 % 8;
f = 25 % 5;
g = 10;
h = 10;
g++;
h--;
}
IF EQUIVALENT OR NOT
#include <stdio.h>
main()
{
int num1, num2;
printf("\n\n");
if (num1 == num2)
printf("EQUIVALENT");
}
IF EQUIVALENT OR NOT 2
#include <stdio.h>
main()
printf("\n");
if (num1 == num2)
printf("TWO NUMBERS ARE EQUIVALENT\n");
if (num1 < num2)
printf("FIRST NUMBER IS SMALLER");
if (num1 > num2)
printf("SECOND NUMBER IS SMALLER");
}
IF ELSE EQUIVALENT OR NOT
#include <stdio.h>
main()
printf("\n");
if (num1 == num2)
printf("TWO NUMBERS ARE EQUIVALENT\n");
if (num1 < num2)
printf("FIRST NUMBER IS SMALLER");
if (num1 > num2)
6
main()
{
int day;
if (day == 1)
{
printf("That day is Monday\n");
printf("Have a nice game.\n");
}
if (day == 2)
{
printf("That day is Tuesday\n");
printf("Have a nice day.\n");
}
if (day == 3)
{
printf("That day is Wednesday\n");
printf("Have a nice day.\n");
}
if (day == 4)
{
printf("That day is Thursday\n");
printf("Have a nice day.\n");
}
if (day == 5)
{
printf("That day is Friday\n");
printf("Have a nice day.\n");
}
if (day == 6)
{
printf("That day is Saturday\n");
printf("Have a nice day.\n");
}
if (day == 7)
{
printf("That day is Sunday\n");
printf("Have a nice day.\n");
}
}
IF HAVE A NICE DAY 2
#include <stdio.h>
7
main()
{
int day;
if (day == 1)
printf("That day is Monday.\n");
if (day == 2)
printf("That day is Tuesday.\n");
if (day == 3)
printf("That day is Wednesday.\n");
if (day == 4)
printf("That day is Thursday.\n");
if (day == 5)
printf("That day is Friday.\n");
if (day == 6)
printf("That day is Saturday.\n");
if (day == 7)
printf("That day is Sunday.\n");
}
IF ELSE HAVE A NICE DAY
#include <stdio.h>
main()
{
int day;
if (day == 1)
printf("That day is Monday.\n");
else if (day == 2)
printf("That day is Tuesday.\n");
8
else if (day == 3)
printf("That day is Wednesday.\n");
else if (day == 4)
printf("That day is Thursday.\n");
else if (day == 5)
printf("That day is Friday.\n");
else if (day == 6)
printf("That day is Saturday.\n");
else if (day == 7)
printf("That day is Sunday.\n");
}
IF ODD OR EVEN
#include <stdio.h>
main()
{
int num;
printf("\n");
if (num % 2 == 0)
printf("EVEN");
}
IF ODD OR EVEN 2
#include <stdio.h>
main()
{
int num;
printf("\n");
if (num % 2 == 0)
printf("EVEN");
9
}
IF ELSE ODD OR EVEN
#include <stdio.h>
main()
{
int num;
printf("\n");
if (num % 2 == 0)
printf("EVEN");
else
printf("ODD");
}
IF JAPAN SEASONS
#include <stdio.h>
main()
{
int month;
if (month == 1)
printf("It is winter.\n");
if (month == 2)
printf("It is winter.\n");
if (month == 3)
printf("It is winter.\n");
if (month == 4)
printf("It is spring.\n");
if (month == 5)
printf("It is spring.\n");
if (month == 6)
printf("It is spring.\n");
if (month == 7)
printf("It is summer.\n");
10
if (month == 8)
printf("It is summer.\n");
if (month == 9)
printf("It is summer.\n");
if (month == 10)
printf("It is autumn.\n");
if (month == 11)
printf("It is autumn.\n");
if (month == 12)
printf("It is autumn.\n");
}
IF JAPAN SEASONS 2
#include <stdio.h>
main()
{
int month;
}
IF JAPAN SEASONS 3
#include <stdio.h>
main()
{
int month;
}
IF POSITIVE OR NEGATIVE
#include <stdio.h>
main()
{
int num;
if (num >= 0)
printf("POSITIVE");
}
IF POSITIVE OR NEGATIVE 2
#include <stdio.h>
main()
{
int num;
printf("\n");
if (num >= 0)
printf("POSITIVE");
if (num < 0)
printf("NEGATIVE");
}
IF ELSE POSITIVE OR NEGATIVE
#include <stdio.h>
12
main()
{
int num;
printf("\n");
if (num >= 0)
printf("POSITIVE");
else
printf("NEGATIVE");
}
IF ELSE BABY TEEN ADULT
#include <stdio.h>
main()
int age;
printf("\n");
main()
{
int num;
13
else
printf("Invalid Input");
}
IF ELSE SEND FAIL TELECOMS
#include <stdio.h>
main()
{
int msgNum;
float charge;
printf("\n");
else
{
printf("Enter a valid number of messages!\n\n");
printf("=============================\n\n");
}
14
return main();
}
IF ELSE UPPERCASE OR LOWERCASE
#include <stdio.h>
main()
{
char alphabet;
printf("\n");
else
printf("UPPER CASE");
}
IF ELSE WEEKDAY OR WEEKEND
#include <stdio.h>
main()
{
int day;
printf("\n");
else
printf("WEEKEND");
}
TELEPONO NG PILIPINO
#include <stdio.h>
main()
{
float charge, rate;
int day, start_time, duration;
printf("\n");
else
{
printf("Duration of call: ");
scanf("%d", &duration);
rate = 1.50; //weekend rate
}