Hello,
i'm a newbie with C
i started learning it like 2 weeks ago by getting a few ebooks that i've found online..
attached with the ebook a booklet full of exercises to test what i've learned for each chapter but without the solutions .. :S
i managed to get through most tests but im stuck at these two.. hope you could point out wht im doing wrong:
Write a complete C program that asks the user to enter continuously a series of words and the
word “end” to stop.
For each word entered, you should output the number of characters of this word and then ask him
to enter the other word.
Finally, when he finished entering all the words, you should output the number of words entered
(excluding “end”)
Code:
#include <stdio.h>
int main(void)
{
char word[256];
char stop[3]="end";
int cnt=0;
printf("Enter a word to know it's number of characters. once finished enter \"end\" to stop\n");
scanf("%s",&word);
while (stop!=word)
printf("The number of characters of %s is %u\n",word,strlen(word));
cnt = cnt++;
else
printf("you've decided to stop. you entered %d words so far.\n",cnt);
return 0;
}
and this is the error:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
tma.c:
Warning W8065 tma.c 10: Call to function 'strlen' with no prototype in function main
Error E2054 tma.c 11: Misplaced else in function main
*** 1 errors in Compile ***
Write a complete C program that calculates the roots of any quadratic equation of the form ax2 +
bx + c = 0 where a, b and c are variables that should be entered by user.
First, if a = 0 then the root is x= -c/b
otherwise, you have to find Δ, Δ=b2 – 4ac
If Δ< 0 there are no roots
If Δ= 0 we have 2 double roots: x1 = x2 = -b/2a
If Δ>0, two roots x1 = (-b-√Δ)/2a and (–b +√Δ)/2a
Hint: you can include math library to use some math functions
Code:
#include "stdio.h"
#include "math.h"
void main()
{
int a,b,c,delta;
float x,x1;
printf("\n Enter values of a,b,c for finding roots of a quadratic eq:\n");
scanf("%d%d%d",&a,&b,&c);
if (a == 0) {
x = -c/b
printf("in this case the root is %f",x);
}
else
delta=b^2-4*a*c
if ( delta<0)
{
printf("there are no roots")
}
if (delta == 0)
{
x= -b/(2*a);
printf("we have double roots %f",x);
}
if (delta>0)
{
x = (-b-sqrt(delta))/2*a)
x1 = (-b+sqrt(delta)/2*a
printf("we have two roots which are %f and %f",x,x1);
}
}
ERROR:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
new.c:
Error E2379 new.c 13: Statement missing ; in function main
Error E2379 new.c 18: Statement missing ; in function main
Warning W8004 new.c 33: 'x' is assigned a value that is never used in function main
Warning W8004 new.c 33: 'delta' is assigned a value that is never used in function main
*** 2 errors in Compile ***