Question
E xample program below shows how to use EOF condition in a while loop. All the questions use EOF testing condition. # include < stdio.h
Example program below shows how to useEOF condition in a while loop. All the questions use EOF testing condition.
#include <stdio.h>
int main()
{
int count , x , y ;
count = 0;
while (scanf("%d%d",&x,&y) != EOF)
{
printf("%d %d ",x,y);
count++;
}
printf("\nTotaly Entered %d x and y values ", count);
return 0;
}
1) Read 3 integer numbers from input environment and
List these integer numbers in ascending and descending order.
Example data could be as follows
23 45 12 your program will give the output as
ascending order 12 23 45
descending orde2 45 23 12
234 423 366 your program will give the output as
ascending order 234 366 423
descending orde2 423 366 234
..
EOF
2)A simple quadratic equation of
a**2 + bx + b = 0 is given
Roots of this equation are
X1 = (-b + Sqrt(b**2 4*a*c))/(2*a)
X2 = (-b - Sqrt(b**2 4*a*c))/(2*a)
Write a C program and find and list the roots X1 and X2.
Read A, B, C from the monitor.
Check the following conditions.
b**2 4 * a * c > 0There are two roots
b**2 4 * b * b = 0Two roots are equal, x1 = x2
b**2 4 * b * b < 0imaginary roots.(just give a message)
Example data could be as follows
If expression is given as
6x**2 + 3*x - 15 = 0
Test your program with the given a b and c values shown below.
6 3 -15
4 0 16
EOF(Use CNT+Z)
Note : use #include <math.h> for power(,), and sqrt() funcions
3)To decide the final result of two football teams , following data is taken from the monitor. First read the names of each team from the monitor and than get the goals of twenty matches from the monitor.
Fenerbahce Galatasaray
2 1
.. ..
.. ..
EOF
To find the final scores, following process must be done for each match.
If first team wins the game, first team gains two points,
If second team wins the game than second team gains threepoints.
If both goals are equal than both team gains one points.
Using simple variable write a C program and determine the final points of each team. If the final points are same than check total number of goals of each team and identify and list the names and total points and total goals of both teams and identify the final winner as Better Team
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started