Tested and experimentet with some more examples
This commit is contained in:
parent
a7c7dc30f7
commit
60c9ceae76
27
average_biggest.c
Normal file
27
average_biggest.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
float nr, sum, biggest;
|
||||
int ant;
|
||||
sum = 0;
|
||||
biggest = 0;
|
||||
ant = 0;
|
||||
|
||||
printf("Write the numbers.\n");
|
||||
printf("Finish with EOF.\n");
|
||||
while (scanf("%f", &nr) == 1)
|
||||
{
|
||||
ant++;
|
||||
sum += nr;
|
||||
if (nr > biggest)
|
||||
{
|
||||
biggest = nr;
|
||||
}
|
||||
}
|
||||
|
||||
printf ("Average: %.3f\n", sum / ant);
|
||||
printf ("Biggest: %.3f\n", biggest);
|
||||
|
||||
return 0;
|
||||
}
|
36
avg_with_function.c
Normal file
36
avg_with_function.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
|
||||
float max(float x, float y)
|
||||
{
|
||||
if (x > y)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
else
|
||||
{
|
||||
return y;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
float number, sum, biggest;
|
||||
int ant;
|
||||
sum = 0;
|
||||
biggest = 0;
|
||||
ant = 0;
|
||||
|
||||
printf("Write the numbers\nFinish with EOF\n");
|
||||
|
||||
while (scanf("%f", &number) == 1)
|
||||
{
|
||||
ant++;
|
||||
sum += number;
|
||||
biggest = max(biggest, number);
|
||||
}
|
||||
|
||||
printf("Average: %.2f\n", sum / ant);
|
||||
printf("Biggest: %.2f\n", biggest);
|
||||
|
||||
return 0;
|
||||
}
|
22
interest3.c
Normal file
22
interest3.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
float cap, want, interest;
|
||||
int year;
|
||||
|
||||
printf("Invested capital: "); scanf("%f", &cap);
|
||||
printf("Want sum: "); scanf("%f", &want);
|
||||
printf("Interest? "); scanf("%f", &interest);
|
||||
|
||||
year = 0;
|
||||
|
||||
while (cap < want)
|
||||
{
|
||||
year = year + 1;
|
||||
cap = cap * (1 + interest / 100);
|
||||
}
|
||||
|
||||
printf("The capital will have to be at the bank for %d years\n", year);
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user