Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
SOFTWARE DELIVERY
AFP – Automação.
Programming Marathon
Challenge 1
Reference: Version ,
Version No: 1.0
Status: Draft
Prime Author: Enzo Pirineli Pacheco
Group: Rocket Team
Document No: 000001
Reference: Version ,
Andersen Consulting Service Delivery
TABLE OF CONTENTS
1. Introduction .............................................................................................................................................. 2
Reference: Version ,
Andersen Consulting Service Delivery
1. Introduction
That document presents the solutions for 10 exercises pertaining to challenge 1 of the programming
:
marathon ... Each solution will present:
- Software requirements -> statement of the exercise.
- Flowchart -> Flowchart of the solution to be developed.
- Program -> code commented on C language.
Reference: Version ,
Andersen Consulting Service Delivery
2. Exercise 1 – Conversor.
2.1 Flowchart:
2.2 Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
printf("The real part of your imaginary number (R) is: %.2f\n", nX);
printf("The imaginary part of your imaginary number (R) is: %.2f", nY);
int main(void) {
printf("Choose Conversion:\n\n");
printf("[1] = Rectangular to polar.\n[2] = Polar to rectangle.");
fflush(stdout);
scanf("%d", &choose);
switch(choose){
case 1:
printf("Please enter the real part of your imaginary number (R): ");
fflush(stdout);
scanf("%f", &number1);
printf("Please insert the imaginary part of your imaginary number (X): ");
fflush(stdout);
scanf("%f", &number2);
Ret2Pol(number1, number2);
break;
case 2:
printf("Please enter the modulo of |Z|: ");
fflush(stdout);
scanf("%f", &number1);
Pol2Ret(number1, number2);
break;
default:
printf("Invalid option :(");
}
return 0;
}
Reference: Version ,
Andersen Consulting Service Delivery
Software Requirements: Write a function that simply prints a message “Hello!! I am from inside
of function” and call the function from main function.
3.1 Flowchart:
3.2 Code:
#include <stdio.h>
#include <stdlib.h>
void SayHello(void){
printf("Hello!! I am from inside of function.");
}
int main(void) {
SayHello();
Reference: Version ,
Andersen Consulting Service Delivery
return 0;
}
Software Requirements: Write a function that takes two integers as input and prints their sum
inside the function.
Reference: Version ,
Andersen Consulting Service Delivery
4.1 Flowchart:
4.2 Code:
#include <stdio.h>
#include <stdlib.h>
int result;
result = N1 + N2;
Reference: Version ,
Andersen Consulting Service Delivery
int main(void) {
NumbersSum(num1, num2);
return 0;
}
Software Requirements: Write a function that takes an integer as input and prints EVEN if the
number is divisible by 2 otherwise prints ODD. Call this function from the main function.
5.1 Flowchart:
5.2 Code:
#include <stdio.h>
#include <stdlib.h>
Reference: Version ,
Andersen Consulting Service Delivery
int main(void) {
int num;
NumberAnalysis(num);
return 0;
}
Software Requirements: Write a function that takes an integer as input and prints all of its
divisors. Call this function from the main function.
6.1 Flowchart:
Reference: Version ,
Andersen Consulting Service Delivery
6.2 Code:
#include <stdio.h>
#include <stdlib.h> :
#include <conio.h>
int main(void) {
int num=0;
NumberDivisors(num);
getche();
return 0;
}
7. Exercise 6 – Calculator
Software Requirements: Suppose you are going to make a simple calculator. Your task is to
prepare four functions- add(), subtract(), multiply() and divide() . Each function takes two
parameters and return the value after applying the corresponding action on those parameters.
Reference: Version ,
Andersen Consulting Service Delivery
7.1 Flowchart:
7.2 Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
float num1, num2;
num1 = num2 = 0;
add(num1, num2);
subtract(num1, num2);
multiply(num1, num2);
divide(num1, num2);
return 0;
}
8. Exercise 7 – findMax.
Software Requirements: Write a function named findMax(). It takes three parameters and return
the maximum value among the three parameters. Call this function from the main function.
Reference: Version ,
Andersen Consulting Service Delivery
8.1 Flowchart:
8.2 Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) { :
float num1, num2, num3;
num1 = num2 = num3 = 0;
printf("Insert 3 numbers:\n");
fflush(stdout);
scanf("%f %f %f", &num1, &num2, &num3);
return 0;
}
9.1 Flowchart:
Reference: Version ,
Andersen Consulting Service Delivery
9.2 Code:
#include <stdio.h>
#include <stdlib.h>
:
void dollarToBDT(float n1){
float result;
result = n1 * 3.86;
printf("%.2f USD = %.2f R$", n1, result);
}
int main(void) {
float doll;
dollarToBDT(doll);
return 0;
}
Software Requirements: Write a function that takes any real number and return its absolute value.
If user gives -5 as parameter, the function will return 5.
Reference: Version ,
Andersen Consulting Service Delivery
10.1 Flowchart:
10.2 Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
float number=0;
AbsoluteValue(number);
return 0;
Reference: Version ,
Andersen Consulting Service Delivery
Software Requirements: Write a function which calculates the area of a: square and another
function that calculates the area of a circle. Ask the user if it is a square or a circle. Then, ask for
parameters and call the respective function to calculate the area.
11.1 Flowchart:
11.2 Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
Reference: Version ,
Andersen Consulting Service Delivery
int main(void) {
float num = 0;
char answer[7];
AreaSquare(num);
return 0;
}
if((answer[0] == 67)||(answer[0] == 99)){
printf("What is the length of the radius of the circle? ");
fflush(stdout);
scanf("%f", &num);
AreaCircle(num);
return 0;
}
else{
printf("Not a valid option");
}
return 0;
}
Software Requirements: Write a function named toUpperCase() which takes a small letter
alphabet as input and return the capital version. If user gives ‘a’ as parameter the function will
return ‘A’.
Reference: Version ,
Andersen Consulting Service Delivery
12.1 Flowchart:
12.2 Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <conio.h>
int main(void) {
char letter;
toUpperCase(letter);
getche();
return 0;
}
Reference: Version ,