Pages

Sunday 29 April 2012

arrays

1Q.      Twenty-five numbers are entered from the keyboard into an array. The number to be searched     is entered through the keyboard by the user. Write a program to find if the number to be searched is present in the array and if it is present, display the number of times it appears in the array.
           #include<stdio.h>
#include<conio.h>
main()
{
      int i;
      int z=0;
      int teja[25]={1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,12,13,14,16,11};
      int search;
      printf("enter letter to search");
      scanf("%d",&search);
      for(i=0;i<=24;i++)
      if(search==teja[i])
      {
                         printf("the number being repeated%d\n",search);
                         z=z+1;
                         }
                         printf("\nno of times%d",z);
      getch();
}



Twenty-five numbers are entered from the keyboard into an array. Write a program to find out how many of them are positive, how many are negative, how many are even and how many odd.
           #include<stdio.h>
#include<conio.h>
main()
{
      int i;
      int z=0,x=0;
      int teja[25]={1,2,3,4,5,6,7,8,9,-1,-2,-3,-4,-5,-6,-7,-8,-9,10,-10,1,2,3,4,5};
      for(i=0;i<=24;i++)
      if(teja[i]>0)
      z=z+1;
                         printf("\n no of positive nos%d",z);
      for(i=0;i<=24;i++)
      if(teja[i]<0)
      x=x+1;
                         printf("\n no of negitive nos%d",x);
      getch();
      }



No comments:

Post a Comment