Experiment
Experiment
INTRODUCTION
GCC
via the command line. It often comes distributed with a linux installation, so if you
are running
Unix or a Linux variant you likely have it on your system. You can invoke gcc on
a source code
gcc filename
The default executable output of gcc is "a.out", which can be run by typing “
./a.out”. It is also
possible to specify a name for the executable file at the command line by using the
syntax
Again, you can run your program with "./outputfile". (The ./ is there to ensure you
run the
Note: If you need to use functions from the math library (generally functions from
math.h such
as sin or sqrt), then you need to explicitly ask it to link with that library with the -l
flag and the
library 'm':
Turbo C/C++
Open Turbo C from your Desktop or Programs menu. Select “File” from Menu bar
and select
If the compilation is success – you will see a “success” message. Else you will see
the number
of errors.
To RUN the program – you may select ->Run from menu and click -> Run
Program:
#include <stdio.h>
void main()
{
printf(“Hello World\n”);
}
Output:
Hello World
Experiment No. 1
Title: Write a C program to declare and initialize variables of different data types
and display their sizes.
Aim: A program to declare and initialize variables of different data types and
display their sizes.
Theory:
Here are some steps to write a program in C to declare and initialize variables of
different data types and display their sizes:
Include the header file <stdio.h> for input/output operations
Start the main() function
Declare and initialize variables of different data types in a single line
Use printf() statements to display the values of the variables in a formatted
string
Use format specifiers like %d, %c, and %f to indicate the data type of the
value
Use the newline escape sequence (\n) to move the cursor to the next line
after each output
Program:
#include <stdio.h>
int main()
{
int age=25;
float height=5.9;
double weight=70.5;
char initial='A';
printf("age:%d\n", age);
printf("height:%.1f\n", height);
printf("weight:%.1lf\n", weight);
printf("initial:%c\n", initial);
return 0;
}
Outputs:
Experiment No. 2
Theory:
Arithmetic operators:
In C, relational operators are the symbols that are used for comparison between
two values to understand the type of relationship a pair of numbers shares. The
result that we get after the relational operation is a boolean value, that tells whether
the comparison is true or false. Relational operators are mainly used in conditional
statements and loops to check the conditions in C programming.
Logical Operators:
Algorithm:
Step 1: Read A, B
Step 2: Let Sum= A+B
Step 3: Let Difference=A-B
Step 4: Let Product=A*B
Step 5: Let Quotient=A/B
Step 6: Let Remainder=A%B
Step 7: Print Sum, Product
Step 8: Stop.
Flowchart:
Start
Declare Variables
Initialize Variables
End
Program:
#include <stdio.h>
int main()
{
int x = 15;
int y = 25;
int result = x+y;
printf(“Sum:%d\n”, result);
return 0;
}
#include <stdio.h>
int main()
{
int x = 50;
int y = 30;
int result = x-y;
printf(“Difference:%d\n”, result);
return 0;
}
#include <stdio.h>
int main()
{
int x = 7;
int y = 6;
int result = x*y;
printf(“Product:%d\n”, result);
return 0;
}
#include <stdio.h>
int main()
{
int a, b, c;
printf(“enter any two values\n”);
scanf("%d%d", &a, &b);
c=a*b;
printf("Ans=%d\t", c);
return 0;
}
Outputs:
#include <stdio.h>
int main()
{
int x = 45;
int y = 9;
nt result = x/y;
printf(“Quotient:%d\n”, result);
return 0;
}
#include <stdio.h>
int main()
{
int x = 29;
int y = 4;
int result = x%y;
printf(“Remainder:%d\n”, result);
return 0;
}