Introduction To C-Programming
Introduction To C-Programming
Arithmetic Operators: +, -, *, /, %
#include <stdio.h>
int main() {
// code
return 0;
}
3. Statements and Expressions
printf("Hello, World!\n");
INPUT STATEMENT IN C- PROGRAMMING
In C programming, input statements are used to take input from the user. The most used function for this
purpose is scanf, which is part of the standard input/output library (stdio.h).
The scanf function reads formatted input from the standard input (keyboard). It requires a format
specifier to determine the type of data to be read and a pointer to the variable where the input will be
stored. Format Specifiers. Here are some common format specifiers used with scanf:
%d for integers
%f for floating-point numbers
%c for characters
%s for strings (character arrays)
%lf for double-precision floating-point numbers e.t.c .
OUTPUT STATEMENT IN C- PROGRAMMING
Basic Output using printfThe printf function prints formatted output to the standard output (usually
the screen).
It requires a format specifier to determine the type of data to be printed and the actual data to be
printed.
Format Specifiers.
%d for integers
%f for floating-point numbers
%c for characters
%s for strings (character arrays)
%lf for double-precision floating-point numbers
%x for hexadecimal numbers
%o for octal numbers
Sample code:
#include <stdio.h>
int main() {
int integer = 42;
float floating_point = 3.14159;
char character = 'A';
char string[] = "Hello, World!";
double double_precision = 2.718281828459;
int hex = 255;
int octal = 255;
// Print an integer
printf("Integer: %d\n", integer);
// Print a character
printf("Character: %c\n", character);
// Print a string
Example of C-Programming
int main() {
int num1, num2, num3;
return 0;
}
C- program to find sum of N-integers.
#include <stdio.h>
int main() {
int N, i, number, sum = 0;
return 0;
}
C program to calculate factorial of a number using iterative.
#include <stdio.h>
int main() {
int n, i;
unsigned long long factorial = 1; // Factorial can be a large number, so we use unsigned
long long
return 0;
}
C program to calculate factorial of a number using iterative.
#include <stdio.h>
// Function prototype
unsigned long long factorial(int n);
int main() {
int n;
return 0;
}
// Function to calculate factorial using recursion
unsigned long long factorial(int n) {
if (n == 0 || n == 1) {
return 1; // Base case: factorial of 0 or 1 is 1
} else {
return n * factorial(n - 1); // Recursive case
}
}