Saturday, July 1, 2017

C++ program to read roll number and marks

This C++ program shows how to declare and use int variables. Program will read roll number and marks from user and display it on screen.

#include<iostream>
using namespace std;
int main()
{
 int marks, rollno;

 cout << "Enter your Roll No:";
 cin >> rollno;

 cout << "Enter your Marks:";
 cin >> marks;

 cout << "\nYour Roll No. is " << rollno << "\n";
 cout << "Your marks are " << marks;
 return 0;
}

Output of program

Enter your Roll No:101
Enter your Marks:90

Your Roll No. is 101
Your marks are 90


Sunday, June 25, 2017

Fahrenheit to Celsius using C++

Write C++ program to read temperature in Fahrenheit and print it in Celsius.

#include<iostream>
using namespace std;

int main()
{
    float f,c;
    cout << "Enter temperature in Fahrenheit(f)=";
    cin >> f;
 
    c = 5 * ( f - 32 ) / 9;
 
    cout<<"Temperature in Celsius = " << c;
 
    return 0;
}

Output

Enter temperature in Fahrenheit(f)=100
Temperature in Celsius = 37.7778


* * * * *

Simple Interest using C++ Program.

C++ program to find simple interest based on given P, R, N and I.

#include<iostream>
using namespace std;

int main()
{
    float P,R,N,I;
 
    cout<<"Enter Principle Amount: ";
    cin>>P;
 
    cout<<"Enter Rate of Interest: ";
    cin>>R;
 
    cout<<"Enter No. of Years: ";
    cin>>N;
 
    I=(P*R*N)/100;
 
    cout<<"Simple interest is : "<< I;
 
    return 0;
}

Output:

Enter Principle Amount: 1000
Enter Rate of Interest: 12
Enter No. of Years: 2
Simple interest is : 240

Friday, June 23, 2017

Using char variable in C++ programs.

Example: Using char variable in C++ programs.

#include<iostream>
using namespace std;

int main()
{
   char name[20];

   cout<<"Enter your name: ";
   cin>>name;

   cout<<"Your Name is : "<< name;
   return 0;
}

Output of program

Enter your name: Earth
Your Name is : Earth

Note: This program will be able to read only one word as your name.


* * * * *

Thursday, June 22, 2017

Using int in C++ Program

Example: Using integer variables in C++ programs.

#include<iostream>
using namespace std;

int main()
{
  int rollno;
  cout<<"What is your Roll Number? ";
  cin>>rollno;
  cout<<"Your Roll Number is "<<rollno;
  return 0;
}

Output of Program

What is your Roll Number? 101
Your Roll Number is 101



* * * * *

Hello World in C++

Let’s begin with a simple C++ program to display "Hello World" on the screen.

Example: Hello World Program in C++



#include <iostream>
using namespace std;
int main()
{
    cout << "Hello World";
    return 0;
}


Output of program

Hello World

Description of Program
  • C++ program starts from the main() function.
  • cout is the standard output stream to print "Hello, World!" on monitor.
  • return 0; indicates program ends and returns 0 to calling program.


* * * * *


Sunday, June 11, 2017

Difference between C and Python

C and Python are general purpose computer programming language. Python is generally preferred for server side scripting. Some of the key difference between C and Python are given below:

Table: Difference between C and Python

C Language
Python Language

Designed by Dennis Richie

Product from Python Software Foundation
C programs are faster but coding is complex and long

Coding is easier and short in Python
C requires type declaration

Python does not require type declaration
C supports in line assignment

Python does not support in line assignment