Saturday, 2 April 2016



Q. Write an algorithm that uses a for loop statement to sum a sequence of integers.  Also find and display the smallest and largest number. Assume that the first integer read specifies the number of values remaining to be entered. Your program should read only one value per input statement.  A typical input sequence might be           5          100     200     300     400            500

Note:-  The 5 indicates that the subsequent 5 values

#include<stdio.h>
#include<conio.h>

void main()
int v,L,S,sum=0,j,n;
{
printf("Enter any number:");
scanf("%d",&v);
printf("Enter the number");
scanf("%d",&n);
L=n;
S=n;
for(j=2; j<=v; j=j+1)
{


scanf("%d",&n);
if(n>L)
L=n;
else if(n<S)
S=n;
sum=sum+n;

}
printf("Sum=%d",sum);
printf("\tLarger=%d\t",L);
printf("Samller=%d",S);
getch();
}

1 comment: