Simple C Programming
Contents
| No. | Description |
|---|---|
| 1 | Quadratic equation |
| 2 | Sum of digits and reverse of a number |
| 3 | Nth Fibonacci number |
| 4 | Positives, negatives, and zeros in a set of n numbers |
| 5 | Evaluate series: 1 + x + x2⁄2! + x3⁄3! + ... + xn⁄n! |
| 6 | Pyramid display using * |
| 7 | Armstrong numbers in a range |
| 8 | Scientific calculator with 8 functions |
| 9 | Pattern display with a number (e.g., N=39174: 3 9 1 7 4) |
| 10 | Leap years in a range |
| 11 | Convert decimal to new base |
| 12 | Standard deviation of n numbers |
| 13 | Location of a number in an array |
| 14 | Append arrays A and B |
| 15 | Currency denomination |
| 16 | Matrix transpose |
| 17 | Upper triangle with 1, lower with -1, diagonal with zero in a 2D array |
| 18 | Matrix multiplication |
| 19 | Factorial of a number using recursion |
| 20 | Prime numbers |
| 21 | Short form of a string |
| 22 | Number of vowels in a string |
| 23 | Mark list of N students using array of structures |
| 24 | String length using pointer |
| 25 | Odd and even numbers to files |
Writing Basic C Program
To start programming in C , you need to understand the structure of a basic C program.
Here’s a simple example:
main.c
#include <stdio.h>
#include <conio.h>
void main() {
int number = 20 ;
clrscr();
printf("the number = %d",number);
getch();
}
Explanation
#include <stdio.h>: This line tells the compiler to include the Standard Input Output library before compiling the program. This library is necessary for functions like printf.
void main(): This is the main function where the execution of the program begins. Every C program must have a main function.
printf("Value = %g",value);: This function prints the text to the screen.
The %g is a datatype representation characters that print the representing data in the console.
Other
| Format Specifier | Description | Example |
|---|---|---|
%d | Integer | int age = 25; |
%f | Double (floating-point) | double pi = 3.14; |
%g | General format | printf("%g", pi); |
%s | Array of characters (string) | char name[] = "Spiderman"; |
%c | Character | char initial = 'S'; |