Largest value of set of given numbers using while loop #c

//The Program Written by Tittu Varghese



//To find largest of set of given numbers using while loop.



#include<stdio.h>

#include<math.h>

#include<conio.h>

void main()

{

int x,l=-32768,i=1,n;

clrscr();

printf("Enter the limit\n");

scanf("%d",&n);

x=l;

printf("Then enter %d numbers\n",n);

while(i<=n)

 {

  scanf("%d",&x);

  if (x>l)

    l=x;

    i=i++;

 }

printf("The largest of given %d numbers is %d",n,l);

getch();

} 



//Here we assign value for "l" as -32768 because it is the smallest value can assign to int (intiger).



//*We can use if,else etc. with while,for etc. loops.

 
//The Program Written by Tittu Varghese



//To find largest and smallest of set of given numbers using while loop.



#include<stdio.h>

#include<math.h>

#include<conio.h>

void main()
{
int x,l=-32768,s=32767,i=1,n;

clrscr();

printf("Enter the limit\n");

scanf("%d",&n);

printf("Then enter %d numbers\n",n);

while(i<=n)
 {
  scanf("%d",&x);

  if(x<s)

    s=x;

  if(x>l)

    l=x;

  i=i++;
 }
printf("The largest of given %d numbers is %d\n",n,l);

printf("The smallest of given %d numbers is %d",n,s);

getch();
}

 

//Here we assign value for "l" as -32768 "s" as 32767 because it is the smallest value can assign to int (intiger).

//and we assign value for "s" as 32767 because it is the largest value can assign to int.

//(**It's a logical program**)  

 


0 comments:

Post a Comment

ShareThis