Wednesday 23 November 2016

Write a program that inputs ten integers in an array. It displays the number of occurrences of each numbers in the array.


       #include<iostream.h>
       #include<conio.h>
       void main()
       {
           int array[10],i,j,c,n;
           cout<<"Enter integers: ";
           for(i=0;i<10;i++)
           cin>>array[i];
           for(i=0; i<10; i++)
           {
             if (array[i]== -1)
             continue;
             n=array[i];
             c=1;
             for(j=i+1 ; j<10; j++)
              {
                if (array[j]==n)
                {
                    c++;
                   array[j]=-1;
                }
             }
            cout<<n<<" is stored "<<c<<" times in the array<<endl;
            }
         getche();

       }

Write a program that inputs the names and monthly salaries of ten employees.........

 Write a program that inputs the names and monthly salaries of ten employees.The program checks annual salary of each person. if annual salary is greater than or equal to Rs. 2,50000/- then it prints name, salary and a message " Tax to be paid" else it prints name, salary and a message " No Tax".



    #include<iostream.h>
    #include<conio.h>
    void main()
    {
       int sal[10],i;
       char name[10][30];
       clrscr();
       for(i=0 ; i<10; i++)
      {
        cout<<"Enter the name of the employee: ";
        cin>>name[i];
        cout<<"Enter the salary of the employee: ";
        cin>>sal[i];
        if(sal[i]*12>=250000)
       {
         cout<<" Name of the employee: "<<name[i]<<endl;
         cout<<" Salary of the employee: "<<sal[i]<<endl;
         cout<<" Tax to be paid! "<<endl;
       }
       else
     {
        cout<<" Name of the employee: "<<name[i]<<endl;
        cout<<" Salary of the employee: "<<sal[i]<<endl;
        cout<<" No Tax! "<<endl;
       }
       }
        getche();
    }

Write a program that uses two arrays to store the roll number and marks of students.....

Write a program that uses two arrays to store the roll number and marks of students.It inputs roll numbers and marks of five students and stores them in corresponding elements of the arrays. The program finally displays the roll number and marks of the students with highest marks.



        #include <iostream.h>
        #include <conio.h>
        int main ()
       {
             int rno[5], marks[5];
             int i;

             cout<< "Enter roll number and marks of the student: " ;
             for(i = 0;i<5;i++)
                cin>>rno[i] >>marks[i];

             max = 0;
             for(i = 1;i <5;i++)
                if(marks[i]>marks[max])
                    max = i;

             cout<< "The student with highest marks: " <<endl;
             cout<< " Roll Number: " <<rno[max]<<endl;
             cout<< " Marks: " <<marks[max];
             return 0;
       }    
               

Write a program that inputs ten integers in an array and counts all prime numbers entered by the user. The program finally displays total number of primes in array.


        
        #include <iostream.h>
        #include <conio.h>
        int main ()
       {
          
          int array[10], i,c,p;
          int count = 0;

         cout<< " Enter integer numbers: " ;
          for(i=0; i<10; i++)
          {
                 p 1;
                for (c 2; c <array[i]/2; c++)
                {
                    if (array[i]%== 0)
                    p = 0;
                    break;
                 }
             if (p == 1)
               count++;
          }
          cout<< " Total numbers of prime numbers in the array is : " <<count;
          return 0;
       } 



Tuesday 22 November 2016

Write a C++ program that input 5 values from user and stores them in array and display sum and average of these values.



        
        #include <iostream.h>
        #include <conio.h>
        int main ()

        {
           int num[5] , i , sum = 0 ;
           float average = 0.0 ;

           for (i = 0; i 5; i++)
           {
                cout<< "Enter  number: " ;
                cin>> num[i];
                sum = sum + num[i];
           }
           
           average =  sum / 5.0;
           cout<< "Sum is:  "<< sum;
           cout<< "Average  is:  "<< average;

          return 0;
           }

Write a program that displays a diamond of asterisks using loop.



       
        #include <iostream.h>
        #include <conio.h>
        int main ()

        {
             int i, j; 

              for (i 0; i <4; i++)
             {
                   for (j 0; j <= 5-i; j++)
                       cout<< " " 

                   for (j = 5-i; j <= 5+i; j++)
                       cout<< "*" 

                  cout<< endl;
              }

               for (i 2; i <= 5; i++)
              {
                    for (j = 0; j <= i; j++)
                        cout<< " " ;

                    for (j = i; j <= (10-i); j++)
                        cout<< "*" ;

                       cout<< endl;
               }
               return 0;
        }


Output: 

                            

Write a program to generate the following pyramid of digits using nested loop



        
        #include <iostream.h>
        #include <conio.h>
        int main ()

        {
             int  mid; 

             for (int i1; i <10; i++)
             {
                   cout<< " " 
                  mid (2 i) - 1;

                  for (int j =1; j <=(10 i); j++)
                     cout<< " " ;  

                  for (j i; j<= mid; j++)
                     cout<<( j %10 ); 

                  for (j (mid 1); j >=i; j--)
                     cout<<( j %10 );

                  cout<< endl;
             }
              return 0;

        }


Output: 


Write a program to print the following output using loop.





         #include <iostream.h>
        #include <conio.h>
        int main ()

        {
           int i , j , k;

            for (i =1; i <=5; i++)
             {
                  for (k =1; k <=5-i; k++)
                   cout<<" . ";

                  for (j =1; j <= 2*i-1; j++)
                    cout<<"B";

                  cout<<"\n";
              }
              return 0;
        }





Write a program that inputs the height of a triangle and display it using loop.


Write a program that inputs the height of a triangle and display it using loop. For example if the user enters height as 5, the program should display the following. 



         #include <iostream.h>
        #include <conio.h>
        int main ()

        {
               int i , n , j;
              
               cout<< "Please Give the value of N as height: " ;
               cin>> n;

                for (i = n; i > 0; i++)
               {
                   for (j = n-i; j > 0; j--)
                   cout<<" ";

                   for (j = 2 i-1; j > 0; j--)
                   cout<<"&";

                 cout<<"\n";
               }

               return 0;
        }    
     

Output: 


Monday 21 November 2016

Write a program to print the following output using loop.





         #include <iostream.h>
        #include <conio.h>
        int main ()

        {
                    int row, pound, star; 
                      int nrows = 6; 
                      for(row = 1; row <= nrows; row++)
                      {
                           for(pound = 1; pound <= nrow-row; pound++)
                                 cout<<"#"; 
                           for(star =1; star <= 2*row-1; star++){
                               if(star == 1 || star == 2*row-1)
                                    cout<<"*"; 
                               else 
                                     cout<<"#"; 
                          for(pound = 1; pound <=  nrow-row; pound++)
                                cout<<"#"; 
                           cout<<endl;
                      }
                }
                  getch();

        }

Write a program that displays the following output using loop


        
        #include <iostream.h>
        #include <conio.h>
        int main ()

        {
           int  i,j;
           char ch 'A';

           for ( i = 1; i <5; i++)
           {
              for (j =1; j<=i; j++)
              {
                  if (j =1)
                       ch = 'A';
                 cout<< ch++;
              }
              cout<< endl ;
           }
           return 0;
        } 

Methods in JAVA Language

 In general, a way may be thanks to perform some task. Similarly, the tactic in Java may be a collection of instructions that performs a sel...