Answered Questions

  • C program to count numbers of positive and negative numbers

    Write a C program using arrays to count the numbers of positive and negative numbers which accepts the inputs as "size of the array" & "elements of the array" and outputs as "number of negative numbers in an array are" & "numbers of positive numbers in an array are" ?

    shweta gupta

    • Jun 25th, 2014

    Code
    1. #include<iostream>
    2. #include<stdio.h>
    3. using namespace std;
    4. int main(){
    5. cout<<"enter the size of array"<<endl;
    6. int size,count_neg=0,count_pos=0;
    7. cin>>size;
    8. int a[size];
    9. for(int i=0;i<size;i++){
    10. cout<<"enter element of a["<<i<<"]=";
    11. cin>>a[i];
    12. if((a[i]>>31)==-1) count_neg++;
    13. else count_pos++;
    14. }
    15. cout<<"total negative numbers "<<count_neg<<" and positive number is "<<count_pos;
    16.  
    17. return 0;
    18. }

    asdasda

    • Aug 11th, 2013

    Code
    1. #include<conio.h>
    2. #include<iostream>
    3.  
    4. using namespace std;
    5.  
    6. int value(int a);
    7.  
    8. int main ()
    9. {
    10.     int a, num, count=0;
    11.    
    12.      cout<<"How many values: ";
    13.      cin>>num;
    14.    
    15.     getch ();
    16.    
    17.    
    18.    
    19. int value(int a);
    20.    
    21.    
    22.     for (a=1;a<=num;a++)
    23.     {
    24.    
    25.         cout<<"Enter value "<<a<<": ";
    26.         cout<<endl;
    27.         }
    28.        
    29.        
    30.         getch ();
    31.         return 0;
    32.         }
    33.        
    34.