(NOTES) C-Program PDF
(NOTES) C-Program PDF
C = (5/9)(F -32)
0 -17
20 -6
40 4
300 148
#include <stdio.h>
#include <stdlib.h>
/* print Fahrenheit-Celsius table for fahr = 0, 20, Comments: explains what program does.
, 300 */ Anything between /* and */, or after // are
ignored by the compiler
int main ( int argc, char * argv[])
{
int fahr, celsius; This is a declaration which announces the
int lower, upper, step; properties of variables; it consists of a type
name and a list of variables.
int means that the variables listed are integers.
lower = 0; /*lower limit of temp table*/ Assignment statements: cause arithmetic to
upper = 300; /* upper limit */ be carried out.
step = 20; /* step size */ Individual statements are separated by
semicolons.
fahr = lower;
while (fahr <= upper) { While loop: loop that repeats one per output
line.
<=, >=, == are to compare.
The condition in parentheses is tested. If it is
true ( fahr <= upper) when the body of the loop
(the 3 statements enclosed in braces) is
executed. Then the condition is retested and if
true, executed again. When the test becomes
false, the loop ends.
celsius = 5 * (fahr-32) / 9;
printf (%d\t&d\n, fahr, celsius); %d specifies an integer argument.
\t is a tab
fahr = fahr + step
}
return EXIT_SUCCESS
}
For Statement
#include <stdio.h>
else
{
printf (IS NOT A LEAP YEAR!\n)
}
}
else
{
printf( IS A LEAP YEAR!\n);
}
else
{
printf( NOT A LEAP YEAR!\n);
}
return EXIT_SUCCESS;
}
isLeapYear function
#include <stdio.h>
#include <stdlib.h>
else
result = 0;
return result;
}
if (isLeapYear(year))
printf ("%d is a leap year!\n", year);
else
printf ("%d is not a leap year!\n", year);
return EXIT_SUCCESS;
}
Swap Function
//Swap Function
#include <stdio.h>
#include <stdlib.h>
m = *first;
*first = *second;
*second = m;
}
return first;
}
//Sort 3 numbers
#include <stdio.h>
#include <stdlib.h>
return EXIT_SUCCESS;
}
//ROT13
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
while (letter) {
scanf ("%c", &letter);
encode (letter);
}
return EXIT_SUCCESS;
}
Void Function
#include <stdio.h>
#include <stdlib.h>
While Loop
#include <stdio.h>
#include <stdlib.h>
#define LINE "***"
}
return EXIT_SUCCESS;
}
While loop
#include <stdio.h>
#include <stdlib.h>
while (start != 1) {
counter ++;
if (start % 2 == 0) {
start = start/2;
printf (" %d", start);
}
else {
start = (3*start + 1);
printf (" %d", start);
}
}
if (start == 1) {
printf ("\n");
}
return counter;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#define STOP -1
#define ALPHABET_SIZE 27
testEncode();
return EXIT_SUCCESS;
}
char encodedChar;