int: For storing integers (whole numbers).
float: For single-precision floating-point numbers.
double: For double-precision floating-point numbers.
char: For storing single characters.
c
Copy code
#include <stdio.h>
int main() {
int age = 25;
printf("Age: %d\n", age);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
float temperature = 36.5f;
double pi = 3.141592653589793;
printf("Temperature: %.1f\n", temperature);
printf("Value of Pi: %.15lf\n", pi);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
char grade = 'A';
printf("Grade: %c\n", grade);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
char letter = 65; // ASCII value for 'A'
printf("Character: %c\n", letter);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
int a = 5, b = 3, sum;
sum = a + b;
printf("Sum: %d\n", sum);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
int isEven = 1; // True
int isOdd = 0; // False
printf("Is even: %d\n", isEven);
printf("Is odd: %d\n", isOdd);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
unsigned int distance = 300;
printf("Distance: %u meters\n", distance);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
long population = 7800000000;
printf("World Population: %ld\n", population);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
int x = 10;
float y = (float)x / 3;
printf("Result: %.2f\n", y);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
int num;
float value;
char symbol;
printf("Enter an integer: ");
scanf("%d", &num);
printf("Enter a float: ");
scanf("%f", &value);
printf("Enter a character: ");
scanf(" %c", &symbol);
printf("You entered: %d, %.2f, %c\n", num, value, symbol);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
char letter = 'A';
printf("Character: %c\n", letter);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
char name[] = "Alice";
printf("Name: %s\n", name);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
char symbol;
printf("Enter a character: ");
scanf("%c", &symbol);
printf("You entered: %c\n", symbol);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
char word[20];
printf("Enter a word: ");
scanf("%s", word);
printf("You entered: %s\n", word);
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
char ch = 'A';
printf("Character: %c, ASCII Value: %d\n", ch, ch);
return 0;
}
c
Copy code
#include <stdio.h>
#include <string.h>
int main() {
char str1[20] = "Hello, ";
char str2[] = "World!";
strcat(str1, str2);
printf("Concatenated String: %s\n", str1);
return 0;
}
c
Copy code
#include <stdio.h>
#include <string.h>
int main() {
char phrase[] = "Programming";
int length = strlen(phrase);
printf("Length of the string: %d\n", length);
return 0;
}
c
Copy code
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "Hello";
char str2[] = "World";
if (strcmp(str1, str2) == 0) {
printf("The strings are equal.\n");
} else {
printf("The strings are not equal.\n");
}
return 0;
}
(Note: strrev is not part of the C standard library, so you may need a custom implementation or use it if your compiler supports it.)
c
Copy code
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "C Programming";
printf("Original String: %s\n", str);
printf("Reversed String: %s\n", strrev(str)); // Works in some environments like Turbo C.
return 0;
}
c
Copy code
#include <stdio.h>
#include <string.h>
int main() {
char source[] = "Copy this text";
char destination[50];
strcpy(destination, source);
printf("Copied String: %s\n", destination);
return 0;
}