C Program to Read Set of Real Numbers from Keyboard & Find the Maximum
To write a C program to read set of real numbers from keyboard and find the maximum among them, you can use a function which takes an array of real numbers and its size as arguments and return the maximum.
Using this function you can write a program to read a set of real numbers from the keyboard and find the maximum number in the array.
Using this function you can write a program to read a set of real numbers from the keyboard and find the maximum number in the array.
C Program to Read Set of Real Numbers and Find the Maximum
Steps:
- Define a function max()
- Under main() function, declare two integers i and n.
- Declare an array a.
- Prompt the message to the user to insert how many elements they want to enter using printf() and allow to enter using scanf().
- Prompt the message and allow to enter the elements.
- Find out the maximum number among them using max() function.
- Print the maximum number along with message.
Code:
#include<stdio.h>
#include<conio.h>
max(float a[], int n);
void main()
{
int i,n;
float a[100];
printf("\n How many elements you want to enter:\n");
scanf("%d",&n);
printf("\n Enter the elements:");
for(i=0;i<n;i++)
scanf("%f",&a[i]);
max(a,n);
getch();
}
max(float a[], int n)
{
int i;
float k, large;
large=a[0];
for (i=1;i<n;i++)
{
if (a[i]>large)
{
k=a[i];
a[i]=large;
large=k;
}
}
printf("Largests element is : %f", large);
return 0;
}
Related Posts:
- Write a Program in C to Determine Whether a Number is Prime or Not.
- How to write a program in C using for Loop?
- How to Create Simple JavaScript Fade Effect Animation?
- Image Slideshow with Navigation Buttons Using Javascript
- How to Create JavaScript Image Slideshow with Links
- Simple JavaScript Fade Effect Animation Using Jquery
- How to Create Simple JavaScript Fade Effect Animation?
- How to Create Pop Up Menus in Oracle Forms ?
- How to Create LOV in Oracle Forms Using Wizard ?
- How to Create Oracle Forms by Using Wizard ?
- How To Make Simple CSS Stylesheet for a Website ?
- How To Create Simple Menu Using CSS ?
C Program to Read Set of Real Numbers from Keyboard & Find the Maximum
Reviewed by Unknown
on
10:40 ص
Rating:
ليست هناك تعليقات: