Problem Statement
Write a c program to calculate second largest number from entered number,
you should not use any array to store these numbers
#include<stdio.h>
int main()
{
int flag,input,max,secmax;
printf("enter the numbers resp. enter ctrl-d in the end ");
flag=1;
while(scanf("%d",&input)!=EOF)
{
if(flag==1)
{
max=input;
secmax=input;
flag++;
}
if(input>max)
{
secmax=max;
max=input;
}
else if(input>secmax)
{
secmax=input;
}
}
printf("the secound maximum input entered is %d \n",secmax);
return 0;
}
Write a c program to calculate second largest number from entered number,
you should not use any array to store these numbers
#include<stdio.h>
int main()
{
int flag,input,max,secmax;
printf("enter the numbers resp. enter ctrl-d in the end ");
flag=1;
while(scanf("%d",&input)!=EOF)
{
if(flag==1)
{
max=input;
secmax=input;
flag++;
}
if(input>max)
{
secmax=max;
max=input;
}
else if(input>secmax)
{
secmax=input;
}
}
printf("the secound maximum input entered is %d \n",secmax);
return 0;
}
No comments:
Post a Comment