0% found this document useful (0 votes)
19 views11 pages

First 5 Programs of C

Uploaded by

swet9736
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views11 pages

First 5 Programs of C

Uploaded by

swet9736
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

1.Write A C PROGRAM TO PRINT SIZE OF ALL DATA TYPES?

Algorithm:

1. Define variables for each data type:

Declare variables of various data types for which you want to find the sizes. You can use
sizeof operator to find the size of each data type

2 Use printf to print the size of each data type:

Use printf statements to print the size of each data type along with a message.

3. Compile and run the program:

Save the program in a .c file (e.g., sizeof_datatypes.c) and compile it using a C compiler.
Then, run the executable to see the sizes of different data types.

4.Exit the program.

Source code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main(void)
{
printf("\n * Size of Integer Data Types***");
printf("\n size of integer is: %d", sizeof(int));
printf("\n size of signed int is : %d", sizeof(signed int));
printf("\n size of unsigned int Is: %d", sizeof(unsigned int));
printf("\n** size of short Integer Data Types**");
printf("\n size of short int is: %d", sizeof(short int));
printf("\n size of signed short int is: %d", sizeof(signed short int));
printf("\n size of unsigned short int is: %d", sizeof(unsigned short int));
printf("\n size of character Data Types *");
printf("\n size of char is: %d", sizeof(char));
printf("\n size of signed char is: %d", sizeof(char));
printf("\n size of unsigned char is: %d", sizeof(unsigned char));
printf("\n\n* Size of Long Integer Data Types *");
printf("\n size of long int is: %d", sizeof(long int));
printf("\n size of signed long int is:%d",sizeof(signed long int));
printf("\n size of unsigned long int is :%d", sizeof(unsigned long int));
printf("\n size of long long int is: %d", sizeof(long long int));
printf("\n size of unsigned long long int is: %d", sizeof(unsigned long long int));
printf("\n size of Float Data Types");
printf("In size of float is: %d", sizeof(float));
printf("\n sige of double is : %d", sizeof(double));
printf ("\n size of long double is: %d",sizeof(long double));
getch();
return 0;
}
Output:
* Size of Integer Data Types***
size of integer is: 4
size of signed int is : 4
size of unsigned int Is: 4
** size of short Integer Data Types**
size of short int is: 2
size of signed short int is: 2
size of unsigned short int is: 2
size of character Data Types *
size of char is: 1
size of signed char is: 1
size of unsigned char is: 1
* Size of Long Integer Data Types *
size of long int is: 4
size of signed long int is:4
size of unsigned long int is :4
size of long long int is: 8
size of unsigned long long int is: 8
size of Float Data TypesIn size of float is: 4
sige of double is : 8
size of long double is: 16
2.Write A C PROGRAM TO PRINT range OF ALL DATA TYPES?

Algorithm:

1. Define variables to store the range information.


2. Print the range of each data type using the predefined macros from <limits.h>
and <float.h>.
3. Compile and run the program to see the range information for various data
types.

* Note that the specific range values may vary depending on your system and
compiler.

4.Exit the program.

Source code:-
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void main()
{
printf("The Range of character Data Types");
printf("\n range of CHAR bit %d", (CHAR_BIT));
printf("\n range of CHAR Maximum is : %d", (CHAR_MAX));
printf("\n range of CHAR minimum is: %d", (CHAR_MIN));
printf("\n range of Integer Data Types");
printf("\n range of INT maximum is:%d", (INT_MAX));
printf("\n range of INT minimum is: %d", (INT_MIN));
printf("\n range of unsigned INT maximum is: %d", (INT_MAX));
printf("\n range of Long Integer Data Type");
printf("\n range of signed CHAR maximum is: %d", (CHAR_MAX));
printf("\n range of signed CHAR minimum is: %d", (CHAR_MIN));
printf("\n range of unsigned CHAR maximum is: %d", (CHAR_MAX));
printf("\n range of Short Integer Data Types");
printf("\n range of short INT maximumis: %hd", (SHRT_MAX));
printf("\n range of short INT minimum is: %hd", (SHRT_MIN));
printf("\n range of unsigned short INT maximum is %d", (SHRT_MAX));
printf("\n range of long INT maximum range is: %ld", (LONG_MAX));
printf("\n range of Long INT minimum range is %ld",(LONG_MIN));
printf("\n range of unsigned long INT maximum range is % lu",
(LONG_MAX));
getch();
}
Output:
The Range of character Data Types
range of CHAR bit 8
range of CHAR Maximum is : 127
range of CHAR minimum is: -128
range of Integer Data Types
range of INT maximum is:2147483647
range of INT minimum is: -2147483648
range of unsigned INT maximum is: 2147483647
range of Long Integer Data Type
range of signed CHAR maximum is: 127
range of signed CHAR minimum is: -128
range of unsigned CHAR maximum is: 127
range of Short Integer Data Types
range of short INT maximumis: 32767
range of short INT minimum is: -32768
range of unsigned short INT maximum is 32767
range of long INT maximum range is: 2147483647
range of Long INT minimum range is -2147483648
range of unsigned long INT maximum range is 2147483647
3.write a c program to determine working operators of c operators?
Algorithm:

1. Define the main function:


Define the main() function, which is the entry point of the C program.
2. .Declare and initialize variables:
Declare and initialize variables to hold values for the operators' operations.
3. Perform logical operations:
Perform logical operations using logical operators (e.g., &&, ||, !) and display the
results.
4. Perform arithmetic operations:
Perform arithmetic operations using arithmetic operators (e.g., +, -, *, /, %) and
display the results.
5. Perform shift operations:
Perform shift operations using shift operators (e.g., <<, >>) and display the results.
6. Perform relational operations:
Perform relational operations using relational operators (e.g., ==, !=, <, >, <=, >=) and
display the results.
7. Perform increment and decrement operations:
Perform increment and decrement operations using increment and decrement
operators (e.g., ++, --) and display the results.
8. Display the results:
Display the results of each operation to demonstrate the behavior of the respective
operators.
9.Exit the program.

Source code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

void main()
{
int a,b;
printf("enter the numbers: \n");
scanf("%d%d",&a,&b);
printf("Arithmatic operators");
printf("sum of numbers a and b is %d",(a+b));
printf("difference of numbers a-b is %d\n",(a-b));
printf("product of numbers a and b %d\n",(a*b));
printf("division of numbers a and b is %d\n",(a/b));
printf("modulus of numbers a/b %d\n",(a%b));
printf("Relational operators");
printf("less than operator %d\n",(a<b));
printf("Greater than operator %d\n",(a>b));
printf(" Equal to operator %d\n",(a==b));
printf("Not equal to operator %d\n",(a!=b));
printf("Increment operators");
printf("pre increment ++a %d\n",(++a));
printf("post increment b++ %d\n", (b++));
printf("Decrement operators");
printf("pre decrement --a %d\n",(--a));
printf("post decrement b-- %d\n",(b--));
printf("logical operators");
printf("AND operator %d\n",(a&b));
printf("OR Operator %d\n",(a|b));
printf("NOT operator %d\n",(!(a>b)));
printf("BIT WISE operator");
printf("AND OPERATOR %d\n",(a&&b));
printf("OR OPERATOR %d\n",(a||b));
printf("left shift operator %d\n",a<<2);
printf("Right shift operator %d\n",b>>3);
printf("exclusive OR operates %d\n",(a^b));
printf("Ternary operator");
printf(" the value of %d\n",(a<b?a:b));
getch();
}
Out put:
enter the numbers:
10 8
Arithmatic operatorssum of numbers a and b is 18difference of numbers a-b is 2
product of numbers a and b 80
division of numbers a and b is 1
modulus of numbers a/b 2
Relational operatorsless than operator 0
Greater than operator 1
Equal to operator 0
Not equal to operator 1
Increment operatorspre increment ++a 11
post increment b++ 8
Decrement operatorspre decrement --a 10
post decrement b-- 9
logical operatorsAND operator 8
OR Operator 10
NOT operator 0
BIT WISE operatorAND OPERATOR 1
OR OPERATOR 1
left shift operator 40
Right shift operator 1
exclusive OR operates 2
Ternary operator the value of 8
4.write a c program to illustrate the math.h functions?

Algorithm:

1. Declare the main function: Define the main function, which is the entry point
of your. Program.
2. Use math.h functions: Inside the main function, you can use various math.h
functions. Here are some examples:
*Square Root (sqrt): Calculate the square root of a number.
*Exponentiation (pow): Calculate the power of a number.
*Trigonometric Functions (sin, cos, tan): Calculate trigonometric values.
*Logarithmic Functions (log, log10): Calculate logarithms.
3. Compile and run the program: Save your C program with a .c extension (e.g.,
math_functions.c).
4. Execute the program: Run the compiled program.
5. Exit the program.

Source code:
#include<stdio.h>
#include<math.h>
void main()
{
double x=4.5,y=5,Pi=M_PI;
printf("Square root value of filter is %lf\n", x,sqrt(x));
printf("exponential value is %lf\n",x,(exp(x)));
printf("natural log of %lf is %lf\n", x,log(x));
printf("log 10 value of %lf is %lf\n",x,log10(x));
printf("absolute value is off %lf\n",x,fabs(x));
printf("ceil value of %lf is %lf\n",x,ceil(x));
printf("floor value of %lf is %lf\n",x,(floor(x)));
printf("power value is %lf\n",(pow(x,y)));
printf("Modular value of %lf is %lf/n",(fmod(x,y)));
printf("sine of X value is %lf\n",sin(x));
printf("Cosine of x value is %lf\n",cos(x));
printf("tan of x value is %lf\n",tan(x));
printf("hyperbolic sine of x is %lf\n",sinh(x));
printf("hyperbolic cosine of x is %lf\n",cosh(x));
printf("hyperbolic tan of x is %lf\n",tanh(x));
printf("arc sine of X is %lf\n",asin(sin(x)));
printf("arc cosine of x is %lf\n",acos(cos(x)));
printf("arc tan of x is %lf\n",atan(tan(x)));
printf("sine of pi %lf\n",sin(M_PI));
printf("cosine of pi is %lf\n",cos(M_PI));
printf(" tan of pi is %lf\n",tan(M_PI));
getch();
}

Output:-
Square root value of filter is 4.500000
exponential value is 4.500000
natural log of 4.500000 is 1.504077
log 10 value of 4.500000 is 0.653213
absolute value is off 4.500000
ceil value of 4.500000 is 5.000000
floor value of 4.500000 is 4.000000
power value is 1845.281250
Modular value of 4.500000 is 0.000000/nsine of X value is -0.977530
Cosine of x value is -0.210796
tan of x value is 4.637332
hyperbolic sine of x is 45.003011
hyperbolic cosine of x is 45.014120
hyperbolic tan of x is 0.999753
arc sine of X is -1.358407
arc cosine of x is 1.783185
arc tan of x is 1.358407
sine of pi 0.000000
cosine of pi is -1.000000
tan of pi is -0.000000
5.write a c program to find if number is even or odd using if-else
condition?

Algorithm:

1. Declare Variables: Declare a variable to store the input number.


2. Input: Prompt the user to enter a number and read the input.
3. Check Even or Odd: Use an if-else statement to check if the number is even
or odd.
* The % operator is used to calculate the remainder when num is divided by 2.
* The % If the remainder is 0, the number is even. Otherwise, it's odd.

4. Output: Display the result.

5. End of Program: Return 0 to indicate successful program execution.

Source code:-
#include<stdio.h>
void main()
{
int n;
printf("enter a number:");
scanf("%d",&n);
if(n%2 ==0)
{
printf("number is even");
}
else
{
printf("number is odd");
}
getch();
}
Output:
enter a number:8
number is even

You might also like