C Basic C Program in C Programming
Basic
C Program In C programming Language
C
Program to Print "Hello World!"
#include
<stdio.h>
#include
<conio.h>
void
main()
{
printf ("Hello World!");
getch();
}
Output: Hello World
C
Program to Print a number or integer
#include
<stdio.h>
#include
<conio.h>
void
main()
{
int n;
printf("Enter
a number or integer: ");
scanf("%d",
&n);
printf("You
entered number or integer is: %d", n);
getch();
}
Output:
Enter
a number or integer: 20
You
entered number or integer: 20
C
Program to Print sum of two number
#include
<stdio.h>
#include
<conio.h>
void
main()
{
int a, b, c;
printf("Enter two number: ");
scanf("%d %d", &a, &b);
c = a + b;
printf("The sum is = %d", c);
getch();
}
Output:
Enter
two number: 10 12
The
sum is = 22
C Program to Print to
addition, subtraction, multiply and division of two number
Or
C Program to make a simple
or arithmetic calculator
#include
<stdio.h>
#include
<conio.h>
void
main()
{
int a, b, c;
printf("Enter two number: ");
scanf("%d %d", &a, &b);
c = a + b;
c = a -
b;
c = a * b;
c = a / b;
printf("The
addition is = %d", c);
printf("The
subtraction is = %d", c);
printf("The
multiplication is = %d", c);
printf("The
division is = %d", c);
getch();
}
Output:
Enter
two number:12 6
The
addition is = 18
The
subtraction is = 6
The
multiplication is =72
The
division is =2
C
Program to Print ASCII Value
#include <stdio.h>
#include <conio.h>
void
main()
{
char a;
printf("Enter a valid
character: ");
scanf
("%c", &a);
printf("ASCII value of valid character %c = %d", c, c);
getch();
}
Output:
Enter
a valid character: f
ASCII
value of valid character f = 102
C
Program to Print Quotient and Remainder
#include
<stdio.h>
#include <conio.h>
void
main()
{
int a, b, quotient, remainder;
printf("Enter dividend number:
");
scanf("%d", &a);
printf("Enter divisor number:
");
scanf("%d", &b);
quotient = a / b;
remainder = a % b;
printf("Quotient is= %d\n",
quotient);
printf("Remainder is= %d",
remainder);
getch();
}
Output:
Enter
dividend number: 22
Enter
divisor number: 4
Quotient
is = 5
Remainder
is = 2
C
Program to print size of variables
#include<stdio.h>
#include <conio.h>
void
main()
{
int integer;
float float;
double double;
char character;
printf("Size of integer: %zu
bytes\n", sizeof(integer));
printf("Size of float: %zu
bytes\n", sizeof(float));
printf("Size of double: %zu bytes\n",
sizeof(double));
printf("Size of character: %zu
byte\n", sizeof(character));
getch();
}
Output:
Size of integer: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of character: 1 byte
C
Program to print swap number using third variables
#include<stdio.h>
#include <conio.h>
void
main()
{
int a, b, temp;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
temp = a;
a = b;
b = temp;
printf("\nAfter swapping first number
= %d\n", a);
printf("After swapping second number =
%d", b);
getch();
}
Output:
Enter
first number: 8
Enter
second number: 10
After
swapping first number = 10
After
swapping second number = 8
C
Program to print swap number without using third variables
#include<stdio.h>
#include <conio.h>
void
main()
{
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
a = a-b;
b = a+b;
b = b-a;
printf("\nAfter swapping first number = %d\n", a);
printf("After swapping second number =
%d", b);
getch();
}
Output:
Enter
first number: 8
Enter
second number: 10
After
swapping first number = 10
After
swapping second number = 8
C
Program to print "Hello World!"
#include<stdio.h>
#include<conio.h>
void main()
{
float radius, area;
printf("\nEnter the radius of
Circle : ");
scanf("%d", &radius);
area = 3.14 * radius * radius;
printf("\nArea of Circle :
%f", area);
getch();
}
}
Output:
Enter
the radius of Circle : 4.0
Area
of Circle : 50.24
C
Program to print system date in your machine.
#include
<stdio.h>
#include <conio.h>
#include <dos.h>
int main()
{
struct date d;
getdate(&d);
printf("Current system date:
%d/%d/%d", d.date_day, d.date_mon, d.date_year);
getch();
return 0;
}
C Program to print Internet Protocol (IP) address in your machine.
#include<stdio.h>
#include<stdlib.h>
int main()
{
system("C:\\Windows\\System32\\ipconfig");
return 0;
}
C Program to shut down or turn off your machine or computer
#include
<stdio.h>
#include <stdlib.h>
int main()
{
system("C:\\WINDOWS\\System32\\shutdown /s");
return 0;
}
Introduction to C Language
Basic
C Program In C programming Language
|
C
Program to Print "Hello World!" |
#include
<stdio.h> #include
<conio.h> void
main() { printf ("Hello World!"); getch(); } |
Output: Hello World |
C
Program to Print a number or integer |
#include
<stdio.h> #include
<conio.h> void
main() { int n; printf("Enter a number or integer: "); scanf("%d", &n); printf("You entered number or integer is: %d", n); getch(); }
|
Output: Enter
a number or integer: 20 You entered number or integer: 20 |
C
Program to Print sum of two number |
#include <stdio.h> #include
<conio.h> void main() { int a, b, c; printf("Enter two number: "); scanf("%d %d", &a, &b); c = a + b; printf("The sum is = %d", c); getch(); } |
Output: Enter
two number: 10 12 The sum is = 22 |
C Program to Print to
addition, subtraction, multiply and division of two number Or C Program to make a simple
or arithmetic calculator |
#include
<stdio.h> #include
<conio.h> void main() { int a, b, c; printf("Enter two number: "); scanf("%d %d", &a, &b); c = a + b; c = a -
b; c = a * b; c = a / b; printf("The addition is = %d", c); printf("The
subtraction is = %d", c); printf("The
multiplication is = %d", c); printf("The
division is = %d", c); getch(); } |
Output: Enter
two number:12 6 The
addition is = 18 The
subtraction is = 6 The
multiplication is =72 The division is =2 |
|
C
Program to Print ASCII Value |
#include <stdio.h> #include <conio.h> void main() { char a;
printf("Enter a valid
character: "); scanf
("%c", &a); printf("ASCII value of valid character %c = %d", c, c); getch(); } |
Output: Enter
a valid character: f ASCII value of valid character f = 102 |
C
Program to Print Quotient and Remainder |
#include <conio.h> void main() { int a, b, quotient, remainder; printf("Enter dividend number: "); scanf("%d", &a); printf("Enter divisor number: "); scanf("%d", &b); quotient = a / b; remainder = a % b; printf("Quotient is= %d\n", quotient); printf("Remainder is= %d",
remainder); getch(); } |
Output: Enter
dividend number: 22 Enter
divisor number: 4 Quotient
is = 5 Remainder is = 2 |
C
Program to print size of variables |
#include<stdio.h> #include <conio.h> void main() { int integer; float float; double double; char character; printf("Size of integer: %zu bytes\n", sizeof(integer)); printf("Size of float: %zu bytes\n", sizeof(float)); printf("Size of double: %zu bytes\n", sizeof(double)); printf("Size of character: %zu byte\n", sizeof(character)); getch(); } |
Output: Size of integer: 4 bytes Size of float: 4 bytes Size of double: 8 bytes Size of character: 1 byte |
C
Program to print swap number using third variables |
#include<stdio.h> #include <conio.h> void main() { int a, b, temp; printf("Enter first number: "); scanf("%d", &a); printf("Enter second number: "); scanf("%d", &b); temp = a; a = b; b = temp; printf("\nAfter swapping first number = %d\n", a);
printf("After swapping second number =
%d", b); getch(); } |
Output: Enter
first number: 8 Enter second number: 10 After swapping first number = 10 After
swapping second number = 8
|
C
Program to print swap number without using third variables |
#include<stdio.h> #include <conio.h> void main() { int a, b; printf("Enter first number: "); scanf("%d", &a); printf("Enter second number: "); scanf("%d", &b); a = a-b; b = a+b; b = b-a; printf("\nAfter swapping first number = %d\n", a); printf("After swapping second number =
%d", b); getch(); } |
Output: |
Enter
first number: 8 Enter
second number: 10 After swapping first number = 10 After swapping second number = 8 |
C
Program to print "Hello World!" |
#include<stdio.h> #include<conio.h> void main() { float radius, area; printf("\nEnter the radius of Circle : "); scanf("%d", &radius); area = 3.14 * radius * radius; printf("\nArea of Circle :
%f", area); getch(); } } |
Output: Enter
the radius of Circle : 4.0 Area
of Circle : 50.24 |
C
Program to print system date in your machine. |
#include <stdio.h>
#include <conio.h> int main()
getdate(&d);
printf("Current system date:
%d/%d/%d", d.date_day, d.date_mon, d.date_year); |
C Program to print Internet Protocol (IP) address in your machine. |
#include<stdio.h> #include<stdlib.h> int main() |
C Program to shut down or turn off your machine or computer |
#include
<stdio.h> |
Comments
Post a Comment