Professional Documents
Culture Documents
d = ++b;
printf("\n%d", d);
printf("\n%d",b);
getchar();
return 0;
}
Dr. Muhammad Yousaf Hamza
Mathematical Functions
printf("%f", y);
getchar();
return 0;
}
Output: 1.000000
printf("%f", y);
getchar();
return 0;
}
Output: 1.000000
Dr. Yousaf, PIEAS
// If given θ is in degree, then first convert it into radians.
#include<stdio.h>
#include<math.h> // use of math.h
#define PI 3.14
int main()
{
float y;
float theta_deg, theta_rad;
theta_deg = 90.0;
theta_rad = (PI/180)*theta_deg;
y = sin(theta_rad); // argument is in radian
printf("%f", y);
getchar(); return 0;
}
Output: 1.000000
Dr. Yousaf, PIEAS
Dr. Yousaf, PIEAS
• log() ……..> natural log
• log10() …………> base-10 logarithm
printf("\n%f",c); // 5.75
getchar();
return 0;
}
Dr. Muhammad Yousaf Hamza
Type Conversion
• C allows for conversions between the basic types, implicitly
or explicitly. It is also called casting.
• A cast is a way of telling one variable type to temporarily
look like another.
• Explicit conversion uses the cast operator.
• Example :
int x=10;
float y, z=3.14;
y=(float) x; /* y=10.0 */
Constants
– Constants are useful for a number of reasons
• Tells the reader of the code that a value does not
change
• Tells the compiler that a value does not change
– The compiler can potentially compile faster code
circum = 2*pi*radius;
getchar();
return 0;
}
radius = 7.3;
pi = 2.9; // Error
circum = 2*pi*radius;
printf("\n%f", circum);
getchar();
return 0;
} Dr. Muhammad Yousaf Hamza
Decisions
if(num%2==0)
printf("\nThe number %d is an even number",num);
if(num%2!=0)
printf("\nThe number %d is an odd number",num);
getchar(); getchar();
return 0;
}
Dr. Muhammad Yousaf Hamza
To decide even/odd
#include<stdio.h>
int main()
{
int num;
printf("Please enter an integer number:\n");
scanf("%d",&num);
else
printf("\nThe number %d is an odd number\n",num);
printf(“Bye”);
getchar(); getchar();
return 0;
} Dr. Muhammad Yousaf Hamza
Flow Chart of If-Else Statements