Sunday, January 13, 2019

Write a C program that accepts integers from the keyboard until we enter a zero or a negative number. The program will output the number of positive values entered, the minimum value, the maximum value and the average of all numbers.

Write a C program that accepts integers from the keyboarduntil we enter a zero or a negative number. The program will output the numberof positive values entered, the minimum value, the maximum value and theaverage of all numbers.

PROGRAM

#include<stdio.h>
main()
{
int max,min,i=0,arr[10],n,e=0;
float k,avg=0;
while(i>=0)
{
printf("Enter an integer:");
scanf("%d",&arr[i]);
i++;
if(arr[i-1]<=0)  break;
}



for(i=0;arr[i]>0;i++)
    {
    arr[i]>0?e++:printf("");
   
}
e>=1?printf("\nTotal number of positive numbers entered is %d\n",e):printf("There are no positive number");

   if(e>=1)
   {
 
   min=arr[0];
   max=arr[0];
   for(i=1;arr[i]>0;i++)
   {
   
    if(min>arr[i])
    {
    min=arr[i];
   
}
else if(max<arr[i])
{
max=arr[i];
}
}

   printf("\nSmall one is:%d\nLarge one is:%d",min,max); 

   for(i=0;arr[i]>0;i++)
   {
    avg=avg+arr[i];
   }
 
 
   for(i=0;arr[i]>0;i++)
   {
    k=avg/(i+1);
   }
printf("\nAverage is %f",k);
}
}
https://www.youtube.com/channel/UCfg0HhLUIrgd_45YaytZrVw

EXPECTED OUTPUT
https://www.youtube.com/channel/UCfg0HhLUIrgd_45YaytZrVw






   
 
   















No comments:

Post a Comment

Manhattan Distance Heuristic

#include<stdio.h> #include<stdlib.h> struct node{  int arr[10][10];  int i,j;  int md; }; int a[10][10]; struct node*...