C programming is a fundamental language for any programmer, and practicing with code snippets is an excellent way to improve your skills. In this article, we'll provide 50 C programming beginner and basic code practice snippets to help you get started or improve your proficiency. It's divided into two parts 25-25 code snippets. C is a powerful and versatile language, widely used in various applications, from operating systems to embedded systems.
|
| 50 C Programming Beginner And Basic Code Practice 25 Code Snippets (Part - 1) - GraphCodeX |
1.Hello World
#include <stdio.h>
#include <conio.h>
void main() {
printf("Hello, World!\n");
getch();
}
Classic C Programming: Hello, World! The "Hello World" program is a traditional and essential starting point for beginners in C programming. It may seem simple, but it lays the groundwork for understanding the basics of programming. Here's why:
2.Printing An Integer
#include <stdio.h>
#include <conio.h>
void main() {
int number = 42;
printf("The integer value is: %d\n", number);
getch();
}
3.Adding Two Numbers
#include <stdio.h>
#include <conio.h>
void main() {
int a=15, b=15, c;
c=a+b;
printf("The sum of %d and %d is: %d\n", a, b, c);
getch();
}
4.User Input Adding Two Numbers
#include <stdio.h>
#include <conio.h>
void main() {
int a=15, b=15, c;
printf("Enter The First Number: ");
scanf("%d", &a);
printf("Enter the second number: ");
scanf("%d", &b);
c = a + b;
printf("The sum of %d and %d is: %d\n", a, b, c);
getch();
}
5.Multiply Floating Point Numbers
#include <stdio.h>
#include <conio.h>
void main() {
int a=20, b=20;
float c=a*b;
printf("%f\n", c);
getch();
}
6.Input User Multiply Floating Point Numbers
#include <stdio.h>
#include <conio.h>
void main() {
int a, b, c;
float c=a*b;
printf("Enter The First Number: ");
scanf("%f", &a);
printf("Enter The First Number: ");
scanf("%f", &b);
printf("The sum of %d and %d is: %d\n", a, b, c);
getch();
}
7.Find ASCII Value
#include <stdio.h>
#include <conio.h>
void main() {
char c;
printf("Enter A Character: ");
scanf("%c", &c);
printf("ASCII Value Of %c = %d", c, c);
getch();
}
8.Swap Two Numbers
#include <stdio.h>
#include <conio.h>
void main() {
int a, b, c;
printf("Enter the first number: ");
scanf("%d", &a);
printf("Enter the second number: ");
scanf("%d", &b);
printf("Before swapping: a = %d, b = %d\n", a, b);
c = a;
a = b;
b = c;
printf("After swapping: a = %d, b = %d\n", a, b);
getch();
}
