Skip to main content

Posts

Showing posts from May, 2018

Write a C C++ program to generate series of natural numbers and their sum

Flowchart

Coding in C

#include<stdio.h>
int main()
{
    int num=1,n,sum=0;
    printf("Enter n: ");
    scanf("%d",&n);
    while(num<=n)
    {
        printf("%d\n",num);
        sum=sum+num;
        num++;
    }
    printf("Sum of series = %d",sum);
    return 0;
}

Coding in C++
#include<iostream> using namespace std; int main() {     int num=1,n,sum=0;     cout<<"Enter n: ";     cin>>n;     while(num<=n)     {         cout<<num<<"\n";         sum=sum+num;         num++;     }     cout<<"Sum of series = "<<sum;     return 0; }
Output

Concepts of Object Oriented Programming

1. Object

Objects are the model of entities related to the problem. They are actually the group of data and functions. They are also called basic run time entities in object oriented system. They represents real world entities of problem such as student, customer, products program has to handle. In real world each entity has some data and some functions. For example if the entity is a student then data would be name, marks, percent etc. and functions would be getdata, putdata etc. The data of one object can only be accessed by the functions of that object. However the functions of one object can be accessed by the functions of another object. Thus in OOP data are hidden from outside objects and remains secure.  
Object समस्या से संबंधित entities के model होते है। वास्तव में object संबंधित data व functions के समूह होते है। इन्हें object oriented system में basic run time entities भी कहते है। ये समस्या के वास्तविक दुनिया के entities जैसे—student, customer, products को represent करते है …

Write a C C++ program to find greater in two given numbers

Flowchart


Coding in C

#include<stdio.h>
int main()
{
    int n1,n2;
    printf("Enter two numbers : ");
    scanf("%d%d",&n1,&n2);
    if(n1>n2)
    {
        printf("Greater number = %d",n1);
    }
    else
    {
        printf("Greater number = %d",n2);
    }
    return 0;
}

Coding in C++
#include<iostream> using namespace std; int main() {     int n1,n2;     cout<<"Enter two numbers : ";     cin>>n1>>n2;     if(n1>n2)     {         cout<<"Greater number = "<<n1;     }     else     {         cout<<"Greater number = "<<n2;     }     return 0; }
Output


C vs C++

The main difference between C and C++ is that C is a procedure oriented programming language whereas C++ is an object oriented programming language. The other differences are as follows:


POP vs OOP

Programming refers to the process of developing programs for solving programming problems. There are mainly two ways of writing programs: Procedure Oriented Programming (POP) and Object Oriented Programming (OOP). Both of them has different thinking and coding method of solving problem.

प्रोग्रामिंग एक ऐसी प्रक्रिया है जिसमें हम programming problems को हल करने के लिए प्रोग्राम बनाते है। प्रोग्राम लिखने के दो तरीके होते है—Procedure Oriented Programming (POP) और Object Oriented Programming (OOP). इन दोनों में समस्या का हल सोचने और कोडिंग करने के अलग-अलग तरीके होते है।


Procedure Oriented Programming (POP)
In POP solution of programming problem is viewed as sequence of tasks to be done such as reading, processing and writing and number of functions are written to accomplish these task. One of the biggest drawback of POP is that it does not create model of entities related to the problem. Another serious drawback of POP is that many data items are declared as global so that it may be use…

Write a C C++ program to generate series of natural numbers from 1 to 5

Flowchart


Coding in C (while)

#include<stdio.h>
int main()
{
    int num=1;
    while(num<=5)
    {
        printf("%d\n",num);
        num++;
    }
    return 0;
}

Coding in C (for)
#include<stdio.h> int main() {     int num;     for(num=1; num<=5; num++)     {         printf("%d\n",num);     }     return 0; }
Coding in C (do while)
#include<stdio.h> int main() {     int num=1;     do     {         printf("%d\n",num);         num++;     }while(num<=5);     return 0; }
Coding in C++ (while)
#include<iostream> using namespace std; int main() {     int num=1;     while(num<=5)     {         cout<<num<<"\n";         num++;     }     return 0; }
Coding in C++ (for)
#include<iostream> using namespace std; int main() {     int num;     for(num=1; num<=5; num++)     {         cout<<num<<"\n";     }     return 0; }
Coding in C++ (do while)
#include<iostream> using namespace s…

Write a C C++ program to find absolute value of given number

Flowchart


Coding in C

#include<stdio.h>
int main()
{
    int n;
    printf("Enter a number: ");
    scanf("%d",&n);
    if(n<0)
    {
        n = -n;
    }
    printf("Absolute value = %d",n);
    return 0;
}

Coding in C++
#include<iostream> using namespace std; int main() {     int n;     cout<<"Enter a number: ";     cin>>n;     if(n<0)     {         n = -n;     }     cout<<"Absolute value = "<<n;     return 0; }
Output