Example
#include <stdio.h>
//Function Prototype
int TestFunction( float x);
//Macros
#define MACRO 0
void main(){
// declare variables
int ij;
int ik;
float fx;
float fy;
//Initialize Variables
ij = 0;
ik = 1;
fx = 0;
fy = 2;
//print out variables
printf("ij is: %i \n", ij);
printf("ik is: %4i \n", ik);
printf("fx is: %f \n", fx);
printf("fy is: %5.2f \n", fy);
//exploring cast
fx = (float) ik;
ij = (int) fy;
//let's print to check it out
printf("fx is: %f \n", fx);
printf("ij is: %i \n", ij);
//reading data at run time
printf("Give me an int: \n");
scanf("%d",&ij);
printf("Give me a float: \n";
scanf("%f",&fx);
//Let's try some math
ik = ij*2;
ik = ik+1;
fy = fx/10;
printf("debug: fy is: %f",fy);
fy = fy +ij;
ik= ij/ik;
fy=5.5;
//A function call
ij = TestFunction(fy);
printf("the function returned: %i \n", ij);
//While Loop
ij = 0;
ik=0;
//set while and exit condition
while(ij<=6)
{
//stuff to repeat while true
ik =ik+1;
printf("I ran %i times",ik);
ik=ik+1;
//update while loop condition
ij=ij+2;
}
//This is the end
printf("ij is: %i \n", ij);
printf("ik is: %4i \n", ik);
printf("fx is: %f \n", fx);
printf("fy is: %5.2f \n", fy);
printf("Program Ended\n\n");
//If Else
if(MACRO){
printf("hello\n");
}else{
printf("byeee!\n");
}
}
int TestFunction(float x)
{
//Declare some variables
int a;
float b;
//Initialize variables
a=0;
b=0;
// Do some math and other stuff
a = (int) x;
b = (float) a;
b=b*2;
b=b+1;
a=b/a;
//return a value
return a;
}