https://www.cs.virginia.edu/~evans/cs216/guides/x86.html
https://wiki.osdev.org/X86-64_Instruction_Encoding
8 lessons
1)
Compiling, linking, executing, debugging and running a C Program
Functions, data types 6)
Input and Output, character strings 5)
Arrays 4)
Operators and precedence
Expressions Types 7)
Control statement 2)
Pointers 3)
Structures
Input Output
Advanced topics
-std=c89 -pedantic
#include <stdio.h>
const int TRUE = 1 ;
const int FALSE = 0 ;
/*
A prime number does not have any prime factors so nothing should
get printed out.Also 1 is not a prime number so does not get counted
as a prime factor. You may use return without any arguments to come out of a
function that returns void.
*/
void iterativePrimeFactor( int x1 )
{
int i1 ;
int newNo = x1 ;
while ( TRUE )
{
i1 = 2 ;
for( i1=2 ; i1 < newNo ; i1++ )
{
if( newNo % i1 == 0 )
{
printf( "%d " , i1 ) ;
newNo = newNo / i1 ;
break ;
}
} //for
//We need to check if the newNo had at least one prime factor
//if it did not then newNo == i1 and we need to check if it
//equals the original number and if it does not then we print it out
if( newNo == i1 )
{
if( newNo != x1 )
printf( "%d" , newNo ) ;
break ;
}
} //while
}
//TO DO
void recursivePrimeFactor( int x1, int orig )
{
//HINT
for ( 2 to 5 )
{
print out 2
6 / 2
recursivePrime( 4 , 8 )
return;
}
3 != 6
print out 3
}
void reverseIterative( int input )
{
int result = 0 ;
while ( input != 0 )
{
int digit = input % 10 ;
result = result * 10 + digit ;
//printf( "digit %d %d\n" , digit , result ) ;
input = input / 10 ;
}
printf( "%d\n" , result ) ;
}
//TO DO
void reverseRecursive( int input , int result )
{
if ( input == 0 )
{
print result
return ;
}
//123
/*
3
12
12 2
32
1
reverseRecursive( 12 , 3 )
reverseRecursive( 1 , 32 )
reverseRecursive( 0 , 321 )
*/
//HINT
}
int main()
{
iterativePrimeFactor(12 ) ;
printf( "\n" ) ;
iterativePrimeFactor(5 ) ;
printf( "\n" ) ;
iterativePrimeFactor(14 ) ;
printf( "\n" ) ;
printf( "---------------\n" );
recursivePrimeFactor( 12, 12 ) ;
printf( "\n" ) ;
recursivePrimeFactor( 5 ,5 ) ;
printf( "\n" ) ;
recursivePrimeFactor( 14, 14 ) ;
printf( "\n" ) ;
printf( "---------------\n" );
reverseIterative ( 132 ) ;
printf( "\n" ) ;
reverseIterative ( 0 ) ;
printf( "\n" ) ;
reverseIterative ( 3 ) ;
printf( "\n" ) ;
printf( "---------------\n" );
reverseRecursive( 132 , 0 ) ;
printf( "\n" ) ;
reverseRecursive( 0 , 0) ;
printf( "\n" ) ;
reverseRecursive( 3 , 0) ;
return 0;
}
/*
Output should be
223
27
---------------
223
27
---------------
231
0
3
---------------
231
0
3
*/
Fill in the "TO DO" parts in the following code and test your code out. The program asks the user for a number of houses and reads input into the dynamically allocated array of structures and prints the data out. A sample input and output is shown .
File: "final.c"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//--------------------------------------------------------------
struct room
{
int noOfWindows ;
int areaOfRoom ;
} ;
//--------------------------------------------------------------
struct house
{
char address[256] ;
struct room livingRoom ;
struct room masterBedroom ;
};
//--------------------------------------------------------------
void readData ( struct house* ptrHouses , int noOfHouses )
{
char buffer[256] ;
int bufSize = 255 ;
//TO DO
}
//--------------------------------------------------------------
void printData ( struct house* ptrHouses , int noOfHouses )
{
//TO DO
}
//--------------------------------------------------------------
int main()
{
int noHouses ;
printf( "Enter the #of houses:" ) ;
scanf( "%d" , &noHouses ) ; getchar() ;
struct house* ptrHouses ;
//TO DO
// Allocate memory dynamically for the houses
readData( ptrHouses , noHouses ) ;
printData ( ptrHouses , noHouses ) ;
}
//--------------------------------------------------------------
Sample Output:
Enter the #of houses:2
Enter data for house #: 1
Enter address:8598 Wicklow Lane Dublin
Enter details for living room noOfWindows area:1 345
Enter details for master bedroom room noOfWindows area:2 300
Enter data for house #: 2
Enter address:1400 Davona Drive Dublin CA
Enter details for living room noOfWindows area:1 321
Enter details for master bedroom room noOfWindows area:2 456
Data for house #: 1
Address: 8598 Wicklow Lane Dublin
Details for living room. Number of Windows:1 Area: 345 sq ft
Details for master bedroom. Number of Windows:2 Area: 300 sq ft
Data for house #: 2
Address: 1400 Davona Drive Dublin CA
Details for living room. Number of Windows:1 Area: 321 sq ft
Details for master bedroom. Number of Windows:2 Area: 456 sq ft