Partially changed file structure to suit VSCode

This commit is contained in:
Louise Brown 2022-10-24 14:01:59 +01:00
parent 1c0a9e7b6a
commit a2c8695634
29 changed files with 30 additions and 21 deletions

View File

@ -3,15 +3,18 @@
int main(void) int main(void)
{ {
// Declare and initialiase as required // Declare and initialise as required
int a = 1,b = 4; int a = 1,b = 4;
float ans; float ans;
ans = a / b; // Perform calculation // Perform calculation
// a and b are integers so the answer will be the result of the integer division
ans = a / b;
// Display answer // Display answer
printf ("\nThe answer is %f",ans); printf ("\nThe answer is %f",ans);
// Exit from program
return 0; return 0;
} }

View File

@ -6,6 +6,7 @@ int main(void)
// declare variable // declare variable
char c; char c;
printf("Input a character: ");
// Wait for a kepypress, store result in c // Wait for a kepypress, store result in c
c = getchar(); c = getchar();

View File

@ -13,12 +13,7 @@
*/ */
float CalculateAreaOfCircle ( float radius ) float CalculateAreaOfCircle ( float radius );
{
float area;
area = M_PI * radius * radius ;
return (area) ;
}
/* Show use of function */ /* Show use of function */
@ -45,3 +40,10 @@ int main (void)
// All done // All done
return 0; return 0;
} }
float CalculateAreaOfCircle ( float radius )
{
float area;
area = M_PI * radius * radius ;
return (area) ;
}

View File

@ -32,8 +32,8 @@ int main (void)
// Prompt for and obtain values // Prompt for and obtain values
printf ("Please enter the radius of the cylinder: "); printf ("Please enter the radius of the cylinder: ");
scanf ("%f", &rad); scanf ("%f", &rad);
ad
printf ("Please enter the length of the cylinder: "); printf ("Please enter the length of the cylinder: ");
scanf ("%f", &len); scanf ("%f", &len);
// Use our function to calculate the area // Use our function to calculate the area

Binary file not shown.

View File

@ -8,13 +8,13 @@
int main() int main()
{ {
char MyName[50]; /* Define a string of 10 characters */ char MyName[11]; /* Define a string of 10 characters */
/* A string */ /* A string */
printf("\nPlease enter your name & press return "); printf("\nPlease enter your name & press return ");
fgets(MyName, 80, stdin); fgets(MyName, 11, stdin);
printf("\nHello %s ",MyName); printf("\nHello %s ",MyName);
return 0; /* End of the program */ return 0; /* End of the program */

View File

@ -15,9 +15,10 @@ int main(void)
char x; /* Define a variable of type char */ char x; /* Define a variable of type char */
printf("Input a character: ");
x = getch(); /* Use getchar to read a keypress and store the */ x = getch(); /* Use getchar to read a keypress and store the */
/* result in 'x' */ /* result in 'x' */
printf("\nDisplaying the char with putchar: ");
putchar(x); /* Display the character stored in 'x' on the */ putchar(x); /* Display the character stored in 'x' on the */
/* screen using putchar */ /* screen using putchar */

View File

@ -8,7 +8,7 @@
int main( void ) int main( void )
{ {
char MyName[50]; /* Define a string of 10 characters */ char MyName[10]; /* Define a string of 10 characters */
/* A string */ /* A string */

View File

@ -1,4 +1,4 @@
/* EEEE1001/H61CAE Chapter 8 */ /* MMME3085 Chapter 8 */
/* Example of a simple if statements */ /* Example of a simple if statements */

View File

@ -11,7 +11,7 @@
int main( void ) int main( void )
{ {
int x = 55; // Define and intialise variable int x = 3; // Define and intialise variable
if ( x == 2 ) if ( x == 2 )

View File

@ -1,4 +1,4 @@
/* EEEE1001/H61CAE Chapter 8 */ /* MMME3085 Chapter 8 */
/* Incorrect use of a single equals sign in an if statement */ /* Incorrect use of a single equals sign in an if statement */

View File

@ -1,4 +1,4 @@
/* EEEE1001/H61CAE Chapter 8 */ /* MMME3085 Chapter 8 */
/* Example of a simple if statements */ /* Example of a simple if statements */

View File

@ -12,7 +12,7 @@ int main( void )
{ {
char c; /* Define an char */ char c; /* Define an char */
c = getch(); /* Get value - no return required*/ c = getch(); /* Get value */
switch (c) /* Start of switch */ switch (c) /* Start of switch */
{ {

View File

@ -29,6 +29,7 @@ int main(void)
for ( j = 0 ; j < 10 ; j++ ) for ( j = 0 ; j < 10 ; j++ )
printf("\nThe value of j is %d",j ); printf("\nThe value of j is %d",j );
printf("\nThe value of j after increment loop is %d",j);
/* The count down loop */ /* The count down loop */
@ -36,6 +37,7 @@ int main(void)
for ( j = 10 ; j > 0 ; j-- ) for ( j = 10 ; j > 0 ; j-- )
printf("\nThe value of j is %d",j ); printf("\nThe value of j is %d",j );
printf("\nThe value of j after decrement loop is %d",j);
return 0; return 0;