FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
2.4k views
in RTU/BTU B.Tech(CSE-I & II Sem) Computer Programming Lab by Goeduhub's Expert (7.6k points)
Programs to learn data type, variables, If-else statement.

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Write Programs to learn data type, variables, If-else statement.

Variables : Variables are nothing but  a name of the memory location. It is used to store data. Its value can be changed, and it can be reused many times.It is a way to represent memory location through symbol so that it can be easily identified . 

Example : 

int i;

char a;

float h;

Data type : data types are declarations for variables. This determines the type and size of data associated with variables.  data types are of three types :

  1. Primitive data type
  2. User defined data type
  3. Derived data type

Data Types are used to:

  • Identify the type of a variable when it declared.
  • Identify the type of the return value of a function.
  • Identify the type of a parameter expected by a function.

 

Primitive data type : 

Data typesDescription
voidAs the name suggests, it holds no value and is generally used for specifying the type of function or what it returns. If the function has a void type, it means that the function will not return any value.
intUsed to denote an integer type.
charUsed to denote a character type.
float, doubleUsed to denote a floating point type.
int *, float *, char *Used to denote a pointer type.

Derived data type : 

Data TypesDescription
ArraysArrays are sequences of data items having homogeneous values. They have adjacent memory locations to store values.
ReferencesFunction pointers allow referencing functions with a particular signature.
PointersThese are powerful C features which are used to access the memory and deal with their addresses.

User Defined data types : 

Data TypesDescription
StructureIt is a package of variables of different types under a single name. This is done to handle data efficiently. "struct" keyword is used to define a structure.
UnionThese allow storing various data types in the same memory location. Programmers can define a union with different members, but only a single member can contain a value at a given time. It is used for
EnumEnumeration is a special data type that consists of integral constants, and each of them is assigned with a specific name. "enum" keyword is used to define the enumerated data type . 

Program : 

#include<stdio.h>

#include<conio.h>

void main()

{

    int a = 4; // positive integer data type

    float b = 5.2324; // float data type

    char c = 'Z'; // char data type

    long d = 41657; // long positive integer data type

    short g = 130; // short +ve integer data type 

    double i = 4.1234567890; // double float data type

    printf("%d",a);

    printf("\n%f",b);

    printf("\n%c",c);

    printf("\n%li",d);

    printf("\n%hi",g);

    printf("\n%lf",i);

}

Output : 

4

5.232400

Z

41657

130

4.123457


If-else statement : 

If the test expression is evaluated to true,

  • statements inside the body of if are executed.
  • statements inside the body of else are skipped from execution.

If the test expression is evaluated to false,

  • statements inside the body of else are executed
  • statements inside the body of if are skipped from execution

 Syntax : 

if (condition) {

// execute if the test expression is true

}

else {

// execute if the test expression is false

}

Example : 

#include<stdio.h>

#include<conio.h>

void main() {

    int i;

    printf("Enter value : ");

    scanf("%d", &i);

    if  (i%2 == 0) {

        printf("%d is even .",i);

    }

    else {

        printf("%d is odd .",i);

    }    

}

Output : 

Enter value : 5

5 is odd .


For more RTU/BTU II Sem Computer Programming Lab  Experiments CLICK HERE

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...