Showing posts with label c-program. Show all posts
Showing posts with label c-program. Show all posts

Tuesday, November 24, 2015

What are the different between object oriented programming language and procedural programming language?

Solution:-

 

Procedure oriented programming(C)

Object oriented programming (C++)

1

Emphasizing in doing (following flowchart)

1

Emphasize on data

2

Large program divided into function

2

Large program divided into objects

3

Data can be freely accessed by function around the program

3

Data are hidden and cannot be accessed by external functions

4

Function can transfer data from one from to other

4

Data are not transferred but object common action is done

5

It is base on Top-down approach

5

It is base on Bottom-up approach

6

Eg:- FORTRAN,COBOL, Pascal, C

6

Eg:-  C++, JAVA, Smalltalk

Tuesday, October 06, 2015

Write a program to display the multiplication table of 1 to 10 using do while loop.

Solution:-
   #include<stdio.h>
   #include<conio.h>
   void main( )
   {
            int row,col,table;
            clrscr( );
            printf("Multiplication table 1 to 10 \n");
            row=1;
            do
            {
                   col=1;
                   do
                   {
                            table=row*col;
                            printf("%d\t",table);
                            col ++ ;
                   }
                   while(col<=10);
                   printf("\n");
                   row ++ ;
            }
            while(row<=10);
            getch( );
   }

Write a program to read two 3 × 3 matrices and calculate and display the sum of those two matrices.

Solution:-
#include<stdio.h>
#include<conio.h>
void main( )
{
       clrscr( );
       int i,j,total;
       int matrix[3][3],matrix1[3][3],sum[3][3];
       printf("Enter the 3*3 matrix \n");
       for(i=0;i<3;i++)
            {
                     for(j=0;j<3;j++)
                    {
                            scanf("%d",&matrix[i][j]);
                     }
             }
        printf("Enter the 3*3 matrix1 \n");
        for(i=0;i<3;i++)
        {
                 for(j=0;j<3;j++)
                {
                       scanf("%d",&matrix1[i][j]);
                 }
        }
        for(i=0;i<3;i++)
       {
                 for(j=0;j<3;j++)
                {
                        sum[i][j]=matrix[i][j]+matrix1[i][j];
                 }
        }
        for(i=0;i<3;i++)
        {
                  for(j=0;j<3;j++)
                 {
    
                        printf("%d\t ",sum[i][j]);
                 }
                 printf("\n");
        }
        getch( );
}
 

Sunday, October 04, 2015

Write a program to take marks of 15 students and print them out in descending order of marks.

Solution:-
     #include<stdio.h>
     #include<conio.h>
     void main( )
     {
            int a[15],temp=0,i,j;
            clrscr( );
            printf("Enter the 15students marks : \n");
            for(i=0;i<15;i++)
            {
                      printf("\n Enter the mark %d \t",i+1);
                      scanf("%d",&a[i]);
             }
             for(i=0;i<15;i++)
             {
                      for(j=i+1;j<15;j++)
                      {
                                 if(a[i]<a[j])
                                 { 
                                           temp=a[i];
                                           a[i]=a[j];
                                           a[j]=temp;
                                  }
                       }
             }
             printf("\n The marks in desending order are : \n");
             for(i=0;i<15;i++)
             {
                        printf("%d \t",a[i]);
             }
             getch( );
     }

 

Saturday, October 03, 2015

Write a program to reverse an integer number. (Hint: if number is 135, it should be displayed as 531)

Solution:-
     #include<stdio.h>
     #include<conio.h>
     void main( )
     {
             clrscr( );
             long int num,rem;
             printf("Enter the integer number: \n");
             scanf("%ld",&num);
             while( num ! = 0 )
             {
                       rem = num % 10 ;
                       printf("%ld",rem);
                       num=num/10;
              }
              getch( );
     }