Programs on Data Types

discussion of some programs on data types in C

Last Reviewed and Updated on February 7, 2020
Posted by Parveen(Hoven),
Aptitude Trainer and Software Developer

My C/C++ Videos on Youtube

Here is the complete playlist for video lectures and tutorials for the absolute beginners. The language has been kept simple so that anybody can easily understand them. I have avoided complex jargon in these videos.

In this chapter we'll discuss some programs that will help you understand the concept of data types in C and C++.

Data types

Write a program using data types (int, char, float, string, double ). Create different variables of different data types and also display them.
#include<iostream>
#include<cstdio>
#include<string>
 
using namespace std;
 
 int main() 
 { 
      int num1 = 100 ;

      char num2 = 'a' ; 

      char num3 = 'A';

      float num4 = 10.235;

      string num5 = "Hoven Training Center";

     double num6 = 23455.09;
 
      cout << " intger number is -- > " << num1 << endl;
 
      cout << " Character is --> " << num2 << endl;
 
      cout << " Single Character cap --> " << num3 << endl;
 
     cout << " float number is -- > " << num4 << endl;
     
     cout << " String is --> " << num5 << endl;
    
    cout << " Double takes float value of higher precision " << num6 << endl;

    cout << " bool takes true or false value " ;
     
     return 0; 
}
 

sizeof operator

Write a program to find the memory space allocated for each C data types ( int, char, float , double )

#include<iostream>
#include<cstdio>

using namespace std; 
 
int main( ) 
 
{ 
         
     cout << "Size of int in bytes = " << sizeof(int) << endl; 

     cout << "Size of char in bytes = " << sizeof(char) << endl;

     cout << "Size of float in bytes = " << sizeof(float) << endl;

     cout << "Size of double bytes = " << sizeof(double) << endl;
         
     return 0 ;
}

Keywords

Write code to display the following keywords using cout and printf

auto double if static 
break else int struct 
case enum long switch
char extern near typedef
const float register union
continue far return unsigned 
default for short void 
do goto signed while 

#include<iostream>
#include<cstdio>

using namespace std; 
 
 
int main () 
{ 
     cout << " auto \t double \t if \t static \n";
     
     cout << " break \t else \t int \t struct \n";
     
     cout << " case \t enum \t long \t switch \n" ;
     
     printf(" char \t extern \t near \t typedef \n ");
     
     return 0 ;
 
 }

Simple interest

Calculate the interest using terms principle = 2000, time = 5, rate = 4.6
#include<iostream>
#include<cstdio>

using namespace std; 
 
int main() 
{ 
    
     int pri, time;
     
     float rate, simpleIn;
     
     pri = 2000;
     
     time = 5;        
         
     rate = 4.6F;
     
     simpleIn = (pri*time*rate)/100;
     
     cout << "simple interest is = " << simpleIn << endl;
     
     return 0 ; 
     
}

Calculate average

Calculate the avg of 5 numbers by taking user input.
#include<iostream>
#include<cstdio>

using namespace std; 
 
int main() 
{ 
      float num1, num2, num3, num4 ,num5 ;
      
      float average;
      
      cout << "Enter first no = " ;
      
      cin >> num1;
     
      cout << "Enter Second no = " ;
      
      cin >> num2;
      
      cout << "Enter third no = " ;
      
      cin >> num3;
      
      cout << "Enter forth no = " ;
      
      cin >> num4;
      
      cout << "Enter fifth no = ";
      
      cin >> num5;
      
     average = (num1+ num2 + num3 + num4 + num5) / 5;
     
     cout << "Average of 5 number is = " << average << ;endl;
                 
      return 0 ;
      
}

Display values using datatypes

Display the values using valid datatypes (25012, 6.02301, A or a, 6.23e-19, Hoven trainings)
#include<iostream>
#include<cstdio>
 
using namespace std; 
 
int main() 
{ 
 
 int integer = 25025;
 
 float decimal = 6.02301f;
 
 char character = 'a' ;
 
 double exponent = 6.23e-19;
 
 string word = "Hoven Trainings";
 
 cout << "integer is = " << integer << endl;
 
 cout << "float is = " << decimal << endl;
 
 cout << "character is = " << character << endl;
 
 cout << "double is = " << exponent << endl;
     
 cout << "string is = " << word << endl;
 
}

Volume of cylinder

Calculate the volume of cylinder using terms radius = 3m , height = 5m.
#include<iostream>
#include<cstdio>
 
using namespace std; 
 
int main() 
{ 
    int r, b, h;
    
    r = 3; h = 5;
    
    b = 3.14 * r * r * h;
    
    printf("Volume is = %d",b);
    
    return 0 ;
 
}

Use of chars datatype

Print "Hoven" using five char variables.
#include<iostream>
#include<cstdio>
 
using namespace std;
 
int main()
{ 
 
     char k1 = 'H'; 
     
     char k2 = 'o';
     
     char k3 = 'v';
     
     char k4 = 'e';
     
     char k5 = 'n';
     
     printf(" %c%c%c%c%c ", k1, k2, k3, k4, k5);
     
     return 0; 
        
}

Use of string datatype

Print "Hoven Trainings" using a string type of variable[a string type is available in C++, not C].

#include<iostream>
#include<cstdio>
#include<string>
 
using namespace std;
 
int main()
{ 
 
    string k1 = "H O V E N T R A I N I N G S";
    
    cout << k1 ;
     
    return 0; 
        
}

Classroom Training

Classroom training in C/C++ is available at our training institute. Click here for details. You can also register yourself here.

Video Tutorial

We have created a video tutorial that can be downloaded and watched offline on your windows based computer. It is in the form of an exe file. No installation is required, it runs by double clicking the file. Since the exe file is hosted on the Google Drive, it should be very safe because Google itself checks for any virus or malware. The video can be watched offline, no internet is required.

Pricing

This single video will cost you USD $5. When you download the video, you will be able to watch the first few minutes for free, as a sample. The video app will prompt you for payment through PayPal and other payment options. If you want ALL VIDEOS, NOT JUST THIS ONE then go here: Complete Set of C/C++ Video Tutorials The entire set is priced at USD $50.

Screenshots

This is a screenshot of the software that should give you a good idea of the available functionality. Click on the image to see a larger view.screenshot of the video being played in the software

Installation

This software doesn't require any installation. Just download and double-click to run it. It doesn't require administrative priviliges to run. It runs in limited access mode, so should be very safe.

supports windows xp and later Supported Operating Systems

These videos can be run on 32-bit as well as 64-bit versions of the Microsoft Windows Operating Systems. Windows XP and all later OS are supported. If you want to run it on Windows XP and Windows Vista, then you must also have the .NET Framework Version 3.5 installed on your machines. Those users who have Windows 7 and later donot have to worry because these operating systems already have the .NET Framework installed on them.

Download Links

IMPORTANT NOTE: This download contains ONLY ONE video. The video is about the topic of this tutorial.

Want ALL Videos? If you want ALL VIDEOS, NOT JUST THIS ONE then go here: Complete Set of C/C++ Video Tutorials. TIP: If you plan to buy these videos, then it would be more economical to buy the entire set.

DISCLAIMER: Even though every care has been taken in making this software bug-free, but still please take a proper backup of your PC data before you use it. We shall not be responsible for any damages or consequential damages arising out of the use of this software. Please use it solely at your own risk.

Please download the software here.
download the video C Programs on Data Types



Creative Commons License
This Blog Post/Article "Programs on Data Types" by Parveen (Hoven) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Updated on 2020-02-07. Published on: 2015-10-05