GithubHelp home page GithubHelp logo

tutorial-01-it21044304's Introduction

Open in Visual Studio Code logo

Tutorial 01

Objectives : Revise writing C Programs

This week we will revisit writing C programs. In IT1050 the programming language you will use C++ is based on the C language and you have to use your C knowledge to write C++ programs

Exercise 1 - Calculations

Write a C program to input marks of two subjects. Calculate and print the average of the two marks.

Program File - Tute01.c โ€ƒ

Exercise 2 - Selection

Write a program to calculate the amount to be paid for a rented vehicle.

  • Input the distance the van has travelled
  • The first 30 km is at a rate of 50/= per km.
  • The remaining distance is calculated at the rate of 40/= per km.

e.g.

Distance -> 20
Amount = 20 x 50 = 1000


Distance -> 50
Amount = 30 x 50 + (50-30) x 40 = 2300 

Program File - Tute02.c

Exercise 3 - Repetition

Write a C program to calculate the sum of the numbers from 1 to n. Where n is a keyboard input.

e.g.

n -> 100
sum = 1+2+3+....+ 99+100 = 5050

n -> 1-
sum = 1+2+3+...+10 = 55

Program File - Tute03.c

Exercise 4 - Functions

Implement the three functions minimum(), maximum() and multiply() below the main() function.

Do not change the code given in the main() function when you are implementing your solution.

int main() {
   int no1, no2;
   printf("Enter a value for no 1 : ");
   scanf("%d", &no1);
   printf("Enter a value for no 2 : ");
   scanf("%d", &no2);
   printf("%d ", minimum(no1, no2));
   printf("%d ", maximum(no1, no2));
   printf("%d ", multiply(no1, no2));
   return 0;
}

Program File - Tute04.c

tutorial-01-it21044304's People

Contributors

it21044304 avatar github-classroom[bot] avatar

Watchers

Nuwan Kodagoda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.