Data Types | Practice | GeeksforGeeks

Working with Data Types is very important in the programming world. Here, we will learn to manipulate the basic data types in CPP.
You will be given four different variables of different data types: a (int), b (float), c (double), l (long long), d (string). Your task is to do step-wise operations as given below:
1. Divide b by c.
2. Divide b by a.
3. Divide c by a (cast to int).
4. Add result of step 3 with l.
5. Print the given string, and the 4th (0-based indexing) character of the string both separated by a space.
Example 1:
Input:
1 2 3 5
gfgc
Output:
0.666667 2 3 8 
gfgc c
Explanation: a = 1, b = 2, c = 3,
l = 5, d = gfgc
b/c = 0.666667
b/a = 2
c/a = 3
(c/a)+l = 8
d = gfgc
d[3] = c


Your Task: 
Don't worry about the taking input. Just complete the function dataTypes(int a, float b, double c, long long l, string d)
Constraints:
1 <= a, b, c <= 106
1 <= l <= 1018

Video:
YouTubeGeeksforGeeks502K subscribersC++ Programming Language Tutorial | C++ Data Types | GeeksforGeeksWatch laterShareCopy linkInfoShoppingTap to unmuteIf playback doesn't begin shortly, try restarting your device.Full screen is unavailable. Learn MoreYou're signed outVideos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.CancelConfirmMore videosMore videosSwitch cameraShareInclude playlistAn error occurred while retrieving sharing information. Please try again later.Watch on0:000:000:00 / 3:54•Live•<div class="player-unavailable"><h1 class="message">An error occurred.</h1><div class="submessage"><a href="https://www.youtube.com/watch?v=ATYsrD-jlxw" target="_blank">Try watching this video on www.youtube.com</a>, or enable JavaScript if it is disabled in your browser.</div></div>
0
mathurpriyansh152 hours ago
void dataTypes(int a, float b, double c, long long l, string d){
    
    // Some statements have been given to you
    // to help you understand data types
    // Please complete the same for correct result
    // Or you can delete and write your own
    float p =  b/c; //do b/c
    
    double q =  b/a; //do b/a
    
    int r =   c/a; //do c/a
    
    long long m = r+l; //do r+l
    
    cout << p << " " << q << " " << r <<" "<< m <<endl;
    
    cout << d << " " << d[3] << endl; //write 3 for index

}
0
iam6983invinciblePremium3 days ago
// { Driver Code Starts
//Initial Template for C++

#include <iostream>
using namespace std;
 
void dataTypes(int, float, double, long long, string);


 // } Driver Code Ends
//User function Template for C++

// Function to check and print data types accordingly
void dataTypes(int a, float b, double c, long long l, string d){
    
    // Some statements have been given to you
    // to help you understand data types
    // Please complete the same for correct result
    // Or you can delete and write your own
    float p = b/c ; //do b/c
    
    double q = b/a ; //do b/a
    
    int r =  c/a ; //do c/a
    
    long long m =r+l ; //do r+l
    
    cout << p << " " << q << " " << r <<" "<< m <<endl;
    
    cout << d << " " << d[3] << endl; //write 3 for index

}

// { Driver Code Starts.
 
int main()
{
    int a;
    float b;
    double c;
    long long l;
    string d;
    
    int t;
    cin >> t;
    
    while(t--){
        
        cin >> a >> b >> c >> l >> d;
    
        dataTypes(a, b, c, l, d);
    }
    
    return 0;
}   // } Driver Code Ends
0
mdsaif04052 months ago
void dataTypes(int a, float b, double c, long long l, string d){
    
    float p =  b/c;     
    double q =  b/a;   
    int r = (int)c/a; 
    long long m = r+l; 

    cout << p << " " << q << " " << r <<" "<< m <<endl;  
    cout << d << " " << d[3] << endl;
}
0
neerajjain071120023 months ago
void dataTypes(int a, float b, double c, long long l, string d){      // Some statements have been given to you   // to help you understand data types   // Please complete the same for correct result   // Or you can delete and write your own   float p = b/c ; //do b/c      double q = b/a ; //do b/a      int r =int(c)/a  ; //do c/a      long long m = r+l; //do r+l      cout << p << " " << q << " " << r <<" "<< m <<endl;      cout << d << " " << d[3] << endl; //write 3 for index
}
-4
adarshchiremath6 months ago
void dataTypes(int a, float b, double c, long long l, string d){      // Some statements have been given to you   // to help you understand data types   // Please complete the same for correct result   // Or you can delete and write your own   float p = b/c ; //do b/c      double q = b/a ; //do b/a      int r =  c/a ; //do c/a      long long m = r+l ; //do r+l      cout << p << " " << q << " " << r <<" "<< m <<endl;      cout << d << " " << d[3] << endl; //write 3 for index
}
0
Lunatic fringe10 months ago
Lunatic fringe
https://uploads.disquscdn.c...
Please Help me,I have test these same cases on Custom input where it is giving correct output. So, I really have no clue that why it's not working correctly while submitting.
0
Sonu Kumar Singh1 year ago
Sonu Kumar Singh
https://media4.giphy.com/me...
0
Sonu Kumar Singh1 year ago
Sonu Kumar Singh
//very easy solution execution time 0.01void dataTypes(int a, float b, double c, long long l, string d){
    // Some statements have been given to you    // to help you understand data types    // Please complete the same for correct result    // Or you can delete and write your own    float p = b/(float)c ; //do b/c
    double q =b/a ; //do b/a
    int r = (int)c/a  ; //do c/a
    long long m =r+l ; //do r+l
    cout << p << " " << q << " " << r <<" "<< m <<endl; cout="" <<="" d="" <<="" "="" "="" <<="" d[3]="" <<="" endl;="" write="" 3="" for="" index="" }="">
0
Vishal Kumar Mahto2 years ago
Vishal Kumar Mahto
Execution Time:0.01void dataTypes(int a, float b, double c, long long l,string d){    float p = b/c ;     double q = b/a ;     int r =  c/a ;     long long m = r+l;    cout << p << " " << q << " " << r <<" "<< m <<endl; cout="" <<="" d="" <<="" "="" "="" <<="" d[3]="" <<="" endl;="" }="" <="" b="">
0
avish mehta3 years ago
avish mehta
// Function to check and print data types accordinglyvoid dataTypes(int a, float b, double c, long long i,string d){    int t;    cin>>t;    cin>>a;    cin>>b;    cin>>c;    cin>>i;    cin>>d;    cout<
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.