Slides


Class Examples on C Programming


Assignment

Please document your learnings about programming, especially in C and Python. Talk about what you have learnt about the different elements and aspects of programming in these languages, some examples that you have worked on your own, what did you find easy or diffcult.

You should also write three programs both in C and Python. Indicate comments clearly on each line of code, take care of indentations. Feel free to google the syntax which has not been discussed in class. You can test your code for correctness in the online compiler shown in class.
1. Write a program to take two integers "a" and "b" as inputs from the user and print their sum.
2. Write a program to take an integer "n" as input and print if it is "odd" or "even".
3. Write a program to take an integer "n" as input from the user and print its factorial.
Note: Factorial refers to the product of an integer and all the integers below it; e.g. factorial four ( 4! ) = 1*2*3*4 = 24.

Deadline

Assignment due on 28th August 2019.

Example of embedding code in a webpage


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(12, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(250);                       // wait for a second
  digitalWrite(12, LOW);    // turn the LED off by making the voltage LOW
  delay(250);                       // wait for a second
}