This topic I am going to start with How to write C Programs (Note: /* */ it is used as remarks)
1.This program is to calculate Fahrenheit and centigrade
#include<stdio.h>
main( )
{
int count; /* a loop control variable */
int farenheit; /* the temperature in Fahrenheit degrees */
int centigrade; /* the temperature in centigrade degrees */
printf("Centigrade to Fahrenheit temperature tablenn");
for(count = -2;count <= 12;count = count + 1 ){
centigrade = 10 * count;
farenheit = 32 + (centigrade * 9)/5;
printf(" C =%4d F =%4d ",centigrade,farenheit);
if (centigrade == 0)
printf(" Freezing point of water");
if (centigrade == 100)
printf(" Boiling point of water");
printf("n");
} /* end of for loop */
}
2.This program will illustrate the how to assignment values to variables
#include<stdio.h>
main( )
{
int a,b,c; /* Interger variables for examples */
a = 12;
b = 3;
c = a + b; /* simple addition */
c = a - b; /* simple subtraction */
c = a * b; /* simple multiplication */
c = a / b; /* simple division */
c = a % b; /* simple modulo (remainder) */
c = 12*a + b/2 - a*b*2/(a*c + b*2);
c = c/4+13*(a + b)/3 - a*b + 2*a*a;
a = a + 1; /* incrementing a variable */
b = b * 5;
a = b = c = 20; /* multiple assignment */
a = b = c = 12*13/4;
}
3. The following example shows how to initialize variables.
#include <stdio.h>
main () {
int sum=33;
float money=44.12;
char letter;
double pressure;
letter='E'; /* assign character value */
pressure=2.01e-10; /*assign double value */
printf("value of sum is %dn",sum);
printf("value of money is %fn",money);
printf("value of letter is %cn",letter);
printf("value of pressure is %en",pressure);
}
1.This program is to calculate Fahrenheit and centigrade
#include<stdio.h>
main( )
{
int count; /* a loop control variable */
int farenheit; /* the temperature in Fahrenheit degrees */
int centigrade; /* the temperature in centigrade degrees */
printf("Centigrade to Fahrenheit temperature tablenn");
for(count = -2;count <= 12;count = count + 1 ){
centigrade = 10 * count;
farenheit = 32 + (centigrade * 9)/5;
printf(" C =%4d F =%4d ",centigrade,farenheit);
if (centigrade == 0)
printf(" Freezing point of water");
if (centigrade == 100)
printf(" Boiling point of water");
printf("n");
} /* end of for loop */
}
2.This program will illustrate the how to assignment values to variables
#include<stdio.h>
main( )
{
int a,b,c; /* Interger variables for examples */
a = 12;
b = 3;
c = a + b; /* simple addition */
c = a - b; /* simple subtraction */
c = a * b; /* simple multiplication */
c = a / b; /* simple division */
c = a % b; /* simple modulo (remainder) */
c = 12*a + b/2 - a*b*2/(a*c + b*2);
c = c/4+13*(a + b)/3 - a*b + 2*a*a;
a = a + 1; /* incrementing a variable */
b = b * 5;
a = b = c = 20; /* multiple assignment */
a = b = c = 12*13/4;
}
3. The following example shows how to initialize variables.
#include <stdio.h>
main () {
int sum=33;
float money=44.12;
char letter;
double pressure;
letter='E'; /* assign character value */
pressure=2.01e-10; /*assign double value */
printf("value of sum is %dn",sum);
printf("value of money is %fn",money);
printf("value of letter is %cn",letter);
printf("value of pressure is %en",pressure);
}
No comments:
Post a Comment