Let us C https://c.praveshagrawal.com Example C Programs Sat, 02 Dec 2023 11:29:22 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 Type Casting https://c.praveshagrawal.com/2023/12/02/type-casting/ https://c.praveshagrawal.com/2023/12/02/type-casting/#respond Sat, 02 Dec 2023 11:29:22 +0000 https://c.praveshagrawal.com/?p=136 #include <stdio.h> int main() { // Type casting double doubleVar = 3.14; int intVar; intVar = (int)doubleVar; printf("Double: %lf\n", doubleVar); printf("Int: %d\n", intVar); return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/type-casting/feed/ 0 Size of Data Types https://c.praveshagrawal.com/2023/12/02/size-of-data-types/ https://c.praveshagrawal.com/2023/12/02/size-of-data-types/#respond Sat, 02 Dec 2023 11:29:08 +0000 https://c.praveshagrawal.com/?p=137 #include <stdio.h> int main() { // Size of data types printf("Size of int: %lu bytes\n", sizeof(int)); printf("Size of float: %lu bytes\n", sizeof(float)); printf("Size of char: %lu bytes\n", sizeof(char)); return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/size-of-data-types/feed/ 0 Constants and Enums https://c.praveshagrawal.com/2023/12/02/constants-and-enums/ https://c.praveshagrawal.com/2023/12/02/constants-and-enums/#respond Sat, 02 Dec 2023 11:28:54 +0000 https://c.praveshagrawal.com/?p=138 #include <stdio.h> // Enum for days of the week enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; int main() { // Constants and enums const double PI = 3.14159; enum Days today = Wednesday; printf("Value of PI: %f\n", PI); printf("Today is day number: %d\n", today); return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/constants-and-enums/feed/ 0 User Input and Type Conversion https://c.praveshagrawal.com/2023/12/02/user-input-and-type-conversion/ https://c.praveshagrawal.com/2023/12/02/user-input-and-type-conversion/#respond Sat, 02 Dec 2023 11:28:40 +0000 https://c.praveshagrawal.com/?p=139 #include <stdio.h> int main() { // User input and type conversion int num1, num2; float result; printf("Enter two integers: "); scanf("%d %d", &num1, &num2); result = (float)num1 / num2; printf("Result of division: %f\n", result); return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/user-input-and-type-conversion/feed/ 0 Character Input and Output https://c.praveshagrawal.com/2023/12/02/character-input-and-output/ https://c.praveshagrawal.com/2023/12/02/character-input-and-output/#respond Sat, 02 Dec 2023 11:27:09 +0000 https://c.praveshagrawal.com/?p=133 #include <stdio.h> int main() { // Character input and output char ch; printf("Enter a character: "); scanf(" %c", &ch); // Note the space before %c to consume any leading whitespace printf("You entered: %c\n", ch); return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/character-input-and-output/feed/ 0 Multiple Inputs and Outputs https://c.praveshagrawal.com/2023/12/02/multiple-inputs-and-outputs/ https://c.praveshagrawal.com/2023/12/02/multiple-inputs-and-outputs/#respond Sat, 02 Dec 2023 11:26:48 +0000 https://c.praveshagrawal.com/?p=131 #include <stdio.h> int main() { // Multiple inputs and outputs int num1, num2, sum; printf("Enter two integers: "); scanf("%d %d", &num1, &num2); sum = num1 + num2; printf("Sum: %d\n", sum); return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/multiple-inputs-and-outputs/feed/ 0 String Input and Output https://c.praveshagrawal.com/2023/12/02/string-input-and-output-2/ https://c.praveshagrawal.com/2023/12/02/string-input-and-output-2/#respond Sat, 02 Dec 2023 11:26:28 +0000 https://c.praveshagrawal.com/?p=126 #include <stdio.h> int main() { // String input and output char name[50]; printf("Enter your name: "); scanf("%s", name); printf("Hello, %s!\n", name); return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/string-input-and-output-2/feed/ 0 Input and Output with Floating-Point Numbers https://c.praveshagrawal.com/2023/12/02/input-and-output-with-floating-point-numbers/ https://c.praveshagrawal.com/2023/12/02/input-and-output-with-floating-point-numbers/#respond Sat, 02 Dec 2023 11:26:13 +0000 https://c.praveshagrawal.com/?p=127 #include <stdio.h> int main() { // Input and output with floating-point numbers float floatNumber; printf("Enter a floating-point number: "); scanf("%f", &floatNumber); printf("You entered: %f\n", floatNumber); return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/input-and-output-with-floating-point-numbers/feed/ 0 Logical AND/OR in If-Else https://c.praveshagrawal.com/2023/12/02/logical-and-or-in-if-else/ https://c.praveshagrawal.com/2023/12/02/logical-and-or-in-if-else/#respond Sat, 02 Dec 2023 11:25:01 +0000 https://c.praveshagrawal.com/?p=124 #include <stdio.h> int main() { // Logical AND/OR in if-else int age; char gender; printf("Enter your age: "); scanf("%d", &age); printf("Enter your gender (M/F): "); scanf(" %c", &gender); // Note the space before %c to consume any leading whitespace if (age >= 18 && gender == 'M') { printf("You are an adult male.\n"); } else if (age >= 18 && gender == 'F') { printf("You are an adult female.\n"); } else { printf("You are not an adult.\n"); } return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/logical-and-or-in-if-else/feed/ 0 Ternary Operator https://c.praveshagrawal.com/2023/12/02/ternary-operator/ https://c.praveshagrawal.com/2023/12/02/ternary-operator/#respond Sat, 02 Dec 2023 11:24:38 +0000 https://c.praveshagrawal.com/?p=118 #include <stdio.h> int main() { // Ternary operator int num1, num2, max; printf("Enter two numbers: "); scanf("%d %d", &num1, &num2); max = (num1 > num2) ? num1 : num2; printf("Maximum number: %d\n", max); return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/ternary-operator/feed/ 0