Simple program to add two numbers in c programming.
#include <stdio.h>
#include <conio.h>
int main()
{
int number1, number2, sum;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
sum = number1 + number2;
printf("%d + %d = %d", number1, number2, sum);
return 0;
}
To download raw file Click Here
Output
Enter two integers: 10 20
10+20=30
Integer Datatype
An integer is a whole number that can be positive, negative, or zero.
Data Type | Memory | Range | Format Specifier |
---|---|---|---|
short int | 2 | -32768 to 32767 | %hd |
unsigned short int | 2 | 0 to 65535 | %hu |
unsigned int | 4 | 0 to 4294967295 | %u |
int | 4 | -2147483648 to 2147483647 | %d |
long int | 4 | -2147483648 to 2147483647 | %ld |
unsigned long int | 4 | 0 to 4294967295 | %lu |
long long int | 8 | -9223372036854775808 To 9223372036854775807 | %lld |
unsigned long long int | 8 | 0 to 18446744073709551615 | %llu |
Character Data Type in C Programming
Character is a data type that holds one character (letter, number, etc.) of data. It must be enclosed with single quotes. e.g. 'A', '4', or '#'
Data Type | Memory | Range | Format Specifier |
---|---|---|---|
char or signed char | 1 | -128 to 127 | %c |
unsigned char | 1 | 0 to 255 | %c |
Floating Point Data Type in C Programming
Float is a shortened term for floating point.
bagavath
#include
#include
#include
int main()
{
//Integer
printf("\nShort int %u Bytes %d To %d",sizeof(short int),SHRT_MIN,SHRT_MAX);
printf("\nunsigned short int %u Bytes 0 To %d",sizeof(unsigned short int),USHRT_MAX);
printf("\nunsigned int %u Bytes 0 To %u",sizeof(unsigned int),UINT_MAX);
printf("\nint %u Bytes %d To %d",sizeof(int),INT_MIN,INT_MAX);
printf("\nlong int %u Bytes %ld To %ld",sizeof(long int),LONG_MIN,LONG_MAX);
printf("\nunsigned long int %u Bytes 0 To %u",sizeof(unsigned long int),ULONG_MAX);
printf("\nlong long int %u Bytes %lld To %lld",sizeof(long long int),LONG_LONG_MIN,LONG_LONG_MAX);
printf("\nunsigned long long int %u Bytes 0 To %llu \n\n",sizeof(unsigned long long int),ULONG_LONG_MAX);
//Character
printf("\nCharacter %u Bytes %d To %d",sizeof(char),CHAR_MIN,CHAR_MAX);
printf("\nCharacter %u Bytes 0 To %d\n\n",sizeof(unsigned char),UCHAR_MAX);
//Float
printf("\nFloat %u Bytes",sizeof(float));
printf("\nDouble %u Bytes",sizeof(double));
printf("\nLong Double %u Bytes\n\n",sizeof(long double));
return 0;
}
Output
Short int 2 Bytes -32768 To 32767
unsigned short int 2 Bytes 0 To 65535
unsigned int 4 Bytes 0 To 4294967295
int 4 Bytes -2147483648 To 2147483647
long int 4 Bytes -2147483648 To 2147483647
unsigned long int 4 Bytes 0 To 4294967295
long long int 8 Bytes -9223372036854775808 To 9223372036854775807
unsigned long long int 8 Bytes 0 To 18446744073709551615
Character 1 Bytes -128 To 127
Character 1 Bytes 0 To 255
Float 4 Bytes
Double 8 Bytes
Long Double 12 Bytes
#include<stdio.h>
int main()
{
int a=10;
char b='$';
float c=12.5f;
long int d=2582l;
int aa=0x41;
float cc=253e-2f;
printf("%d \n %d \n%0.2f",a,b,c);
return 0;
}
0 comments:
Post a Comment