Pouvez vous m'aider ! Please - C - Programmation
Marsh Posté le 17-11-2011 à 11:06:40
Because you didn't show up any work done for this assignment.
A+,
Marsh Posté le 19-11-2011 à 12:49:47
Hi again, sorry for that you have a point so this is my solution for this programs so please correct if am wrong
Ex01:
#include<stdio.h>
#include<conio.h>
main() {
float n1,n2,n3,moyenne;
cout << "donner les trois note" ;
cin >> n1 >> n2 >> n3 ;
moyenne = (n1+n2+n3)/3 ;
cout << "moyenne = " << moyenne ;
system ("pause" );
}
Marsh Posté le 19-11-2011 à 15:45:54
Code :
|
That was not too bad, but you mixed C and C++
A first version in C:
Code :
|
This will work, but only if the input is correct.
In C, you must check the validity of external data.
The external data comes from the scanf function, so you need to check its manuel page
in order to know how this function signals that something bad occurred with it.
Citation : Return Value |
So now you can have a user-proof version:
Code :
|
You can enhance it with a better version, conformant to standards for the return value:
Code :
|
and then be smarter for the error message:
Code :
|
If you want the moyenne with only two digits after the decimal, just replace
printf("La moyenne est: %f\n", moyenne);
with
printf("La moyenne est: %.2f\n", moyenne);
You can then try to enhance this exercise:
Read a fixed number of notes (here it is 3, make it work for any other number) and use an array to store the notes and use a loop to read the input.
Read a variable (but limited by a maximum number) number of notes
A C++ program is very different.
for example, a very minimal program (similar to the first one I wrote, with no error checking, etc) woud be:
Code :
|
Compare with the equivalent C program:
Code :
|
A+,
Marsh Posté le 21-11-2011 à 19:07:52
Wow! Thank You That Was Amazing, it was the best explanation i ever seen, Honestly Wow!!
Marsh Posté le 22-11-2011 à 20:56:13
Hi Again, more questions ^^
we solved EX02 but i found it complicated can you help me please
Marsh Posté le 22-11-2011 à 22:34:41
It is just because you don't understant the fundamental definition of a multiplication.
A multiplication is just the repetition of an addition:
a + a + ... + a, n times, is n*a. This is how you define a multiplication, the real meaning of a multiplication: repeating an addition.
So now, lets have to numbers, a and b, and suppose that a <= b.
as a is less than b, lets try to remove it as much as we can from b (we do the reverse of a multiplication: we repeat a substraction).
we do b -a, if this is positive, we do b - a - a, etc
at some point, we will have b - a - a - ... - a >= 0 and if we substract one times more a, we will have a negative number:
b - a - a - ... - a >= 0 and
b - a - a - ... - a -a < 0
this is the same as
b - (a + a + ... + a) >= 0 and
b - (a + a + ... + a) -a < 0
lets count the number of times that we have a in (a + a + ... + a) an name q that count.
By definition of what is a multiplication, this (a + a + ... + a) is a*q
So we have
b - a*q >= 0 and
b - a*q -a < 0 wich is the same as b - a*q < a
lets name r the number b - a*q
we have
r >= 0 and
r < a
which can be written on a unique line as
0 <= r < a
We have b = b - a*q + a*q = r + a*q and 0 <= q < a. q is called the quotient and r the remainder of the division of b by a.
We have seen that by substracting a as much as we can, and counting the number of times we substracted, we can get the quotient and the remainder:
Algorithm:
[quotient = 0, remainder = b] (initial conditions)
loop
if remainder -a < 0 (we cannot substract a one time more) exit loop
(else)
remainder = remainder - a (we substract a one more time)
quotient = quotient + 1 (we increase the number of times that we have substracted a)
end loop
when we exit the loop, we have the quotient (the biggest number of times that we can substract a and remain positive) and the remainder (what remains when we cannot substract a one time more).
Note: The test if remainder -a < 0 is the same as the test if remainder < a , which simpler to write.
This is straightforward in C:
Code :
|
which is just what is done in your exercise (there is an obvious first part, where the iSaisi1 and iSaisi2 are associated with a and b in order to have a <= b)
A+,
Marsh Posté le 29-11-2011 à 20:05:34
Hi Again,
THank You for your help Teacher ^^
but this time i really don't know even how to start this one so please please help me here it is :
http://www.iimmgg.com/image/32fbda [...] 28236c714c
Number Five please i've done the last ones i m gonna upload them later but now please help me with this one i promise you it will be the last time if i'm bothering You
Marsh Posté le 29-11-2011 à 22:43:59
So the number 5 exercise asks what? to calculate y such that when x ...
So you are going to implement a function f, which, when you give a value x, returns with a value y that is calculated (from x) according to the formulas given.
So as you are going to write a function, lets name it: function5.
In input: x, a number. It is a real number, so in C, we will use the float type.
In output, y, a number. It is a real number, so in C, we will use the float type.
So we have the prototype of function5:
float function5(float x);
and we will use it in main as:
...
float x, y;
printf("Donnez la valeur de x: " );
lus = scanf("%f", &x);
.....
y = function5(x);
printf("La valeur de y est: %f, y);
...
So now, you have to implement function5, ie write its code:
float function5(float x) {
float y; // we will put the calculation in it and return it
....
return y;
}
function5 is such that "y is x + 8 if x <= 10"
so we have a test: if x <= 10 , which gives in C: if (x <= 10)
and if the test is true, y is x + 8, which gives in C: y = x+8;
so combining both part, we get:
if (x <= 10) {
y = x+8;
}
and if x is not less or equal than 10, we have something else, so we can write
if (x <= 10) {
y = x+8;
}
else {
....
}
so we have the beginning of the function:
float function5(float x) {
float y; // we will put the calculation in it and return it
if (x <= 10) {
y = x+8;
}
else {
....
}
return y;
}
I hope this helps
A+,
Marsh Posté le 30-11-2011 à 07:57:36
Hello
Be carefull, main() isn't "void" because is "int"...
Marsh Posté le 04-12-2011 à 22:59:21
Hello sir Thank you for every thing u have done for me God bless you
XD one last question Sir
programme qui calcul x power n with out using (* , ^)
no multiplication no power !!
How !!? if u can en PACAL et C++
Thank You and sorry .
Marsh Posté le 05-12-2011 à 02:25:43
I suppose that x and n are two positive integer (you can enhance it in the case where x is negative)
Code :
|
The algorithm is simple:
First, you create a function mult(x, y) which calculates the product of x by y (we saw last time that it can be made with additions, adding y times the number x )
now lets have look:
mult(1, x) = 1*x = x = x^1;
mult(mult(1, x), x) = mult(x, x) = x*x = x^2;
mult(mult(mult(1, x), x), x) = mult(x*x, x) = x*x*x
..........
mult(...mult(mult(1, x), x), x) = mult(x*...*x, x) = x*...*x*x = x^n, when we have n times a call to the function mult
So we can write the algorithm:
exp = 1
loop n times
exp = mult(exp, x)
end loop
This is the most efficient way to calculate it here.
Note:
I suspect that you are expected to use the (less efficient) recursive algorithm:
exp(x, n) = 1 if n = 0 (and x is not 0)
exp(x, n) = mult(exp(x, n-1), x) if n is not 0
A+,
Marsh Posté le 05-12-2011 à 10:45:33
Thank You that Was amazing God bless You TeaCher ^^
Sorry for bothering You have a niCe Day Sir .
Marsh Posté le 06-12-2011 à 13:34:32
Pour ma dernière réponse, s'il coupe-colle mon code, c'est sur que son prof va penser qu'il est de lui
Tu remarqueras qu'a chaque fois, c'est une longue explication pédagogique que je fais, pas un bout de code sec.
C'est bien Shipon, ton avatar?
EDIT: Ah oui, au vu du profil, c'est clair.
A+,
Marsh Posté le 06-12-2011 à 13:52:07
non mais ok pour les explications, mais pour l'exo 5 il n'a rien proposé a part un vague "ouais je l'ai fait"... ^^
(Et oui, c'est Shipon, je sais que tu es fan de Stellvia )
Marsh Posté le 06-12-2011 à 14:01:56
Oui, quelque peu fan (j'ai même la version DVD JAP non sous titrée ). Je regretterais éternellement qu'ils aient annulé la S2.
Il avait quand même l'air d'avoir fait un minimum d'efforts.
Le plus souvent, c'est dans le topic perl que je fais le boulot à la place, pédagogiquement aussi, mais surtout parce qu'il est difficile au débutant de rentrer dans ce langage (peu de bouquins d'initiation à Perl bien foutus).
A+,
Marsh Posté le 12-12-2011 à 21:53:04
don't u worry i never do that ^^ , + we have a stupid teacher im not doing this exercises to please him its for my self although its hard to much ur explanation but i try to do it my way So i really thank u about every thing Peace
Marsh Posté le 19-12-2011 à 22:40:33
Cool, and do you expect us to show up for your exams ?
Marsh Posté le 17-01-2012 à 19:56:02
Hey All,
"Cool, and do you expect us to show up for your exams ?" I told Ya i'm not like that man i train my self not to please teachers so please understand that cuz u seem like u don't ^^ any way ..
i did some exs Hope they're correct so i leave that to you Pros ^^
Marsh Posté le 17-01-2012 à 20:11:13
So please take a look :
Code :
|
Code :
|
Code :
|
Well i blocked in this one, So please just how to start it will be great ^^:
Without Using tables Cuz we didn't get there yet .
Thank You
Marsh Posté le 17-01-2012 à 23:39:41
Hi Again,
Well Finaly i think i did it right(i guess) :
Code :
|
Marsh Posté le 18-01-2012 à 01:13:06
First exercice.
I already told you! You must choose between a C++ program:
Code :
|
and a C program:
Code :
|
But try not to mix both languages.
Code :
|
A+,
Marsh Posté le 16-11-2011 à 23:41:48
bonjour a tous, c'est ma première année informatique et j'ai des exercices concernant language c :
Ex01:
Programme calculant la moyenne de 3 notes données d’un
étudiant.
Ex02:
Programme calculant le reste et le quotient de la division
entière de 2 entiers donnés.
Ex03:
Programme résolvant l’équation Ax2+Bx+C=0.
Ex04:
Programme résolvant une équation du 1er degré : Ax+B=0
Donc svp Je n'oublierai pas votre aide