Problem #1 Pointers should not be used for this program. Write a single C progra
ID: 651658 • Letter: P
Question
Problem #1
Pointers should not be used for this program.
Write a single C program that reads up to 21 floating-point numbers entered at the keyboard into a onedimensional array and provides the count of both positive and negative numbers and the total of the negative and the positive numbers. The program will stop reading sets of values when the sentinel 0 is entered. Pointers should not be used for this program.
The program should not accept a negative quantity. That would be no participation.
The program should not accept a quantity above 21. That is too much participation.
No <isostream> use <stdio.h> instead.
Sample output:
Explanation / Answer
this is the solution .......
#include
int main()
{
int p_nArr[20]={0};
int nCount_Pos = 0;
int nCount_Neg = 0;
int num=0;
int SIZEOFARRAY= 0;
int index;
printf("nEnter the Size of the array");
scanf("%d",&SIZEOFARRAY);
printf("nEnter the elements ::n");
for( index = 0; index < SIZEOFARRAY; index++ )
{
scanf("%d",&p_nArr[index]);
if (p_nArr[index] > 0 )
nCount_Pos++ ;
else if (p_nArr[index] < 0 )
nCount_Neg++;
}
if ( nCount_Neg > 0)
{
printf("nNumber of negative numbers in the array are :: %dn", nCount_Neg);
for( index = 0; index < SIZEOFARRAY; index++ )
{
if (p_nArr[index] < 0 )
printf("%d ",p_nArr[index]);
}
}
if ( nCount_Pos > 0 )
{
printf("nNumber of Positive numbers in the array are :: %dn",nCount_Pos);
for( index = 0; index < SIZEOFARRAY; index++ )
{
if (p_nArr[index] > 0 )
printf("%d ",p_nArr[index]);
}
}
getch();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.