1. Simple "Hello World!" Program in C
#include<stdio.h>
int main()
{
printf("Hello world!\n");
return 0;
}
---------------------------------------------------------------------
2. simple printf example
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\tMy Introduction\n");
printf("Hey Friends I m Ram\n");
printf("I m student");
printf("\nC programming is best for me.");
printf("\t");
getch();
return 0;
}
Output:-
--------------------------------------------------
3. print integer example
#include <stdio.h>
int main()
{
int a;
printf("Enter a integer number:");
scanf("%d", &a);
printf("\nYou have Entered number: %d\n", a);
return 0;
}
Output:-
------------------------------------------------------
4. simple addition of static value
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10,b=4,c;
clrscr();
c=a+b;
printf("c=%d",c);
getch();
}
Output:-
5. simple division example
#include<stdio.h>
#include<conio.h>
main()
{
int a=20,b=5,c;
clrscr();
c=a/b;
printf("division=%d",c);
getch();
return 0;
}
Output:-
6. Addition Substraction Multiplication and division example
#include<stdio.h>
#include<conio.h>
void main()
{
int a=25,b=7,c,r;
float d;
clrscr();
printf("The value of A is: %d",a);
printf("\nThe value of B is: %d",b);
c=a+b;
printf("\n\nAddition is: %d\n",c);
c=a-b;
printf("Subtration is: %d",c);
printf("\nMultipliction is: %d",a*b);
d=a/b;
printf("\nDivision is: %.4f",d);
r=a%b;
printf("\nRemainder is: %d",r);
getch();
}
Output:-
7. Program to using scanf function.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
float c;
clrscr();
printf("Enter the value of A:");
scanf("%d",&a);
printf("Enter the value of B:");
scanf("%d",&b);
printf("Enter the value of C:");
scanf("%f",&c);
printf("\n\nA=%d\nB=%d\nC=%f",a,b,c);
getch();
}
8. Addition of two numbers using scanf
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter the value a:\n");
scanf("%d",&a);
printf("enter the value b:\n");
scanf("%d",&b);
c=a+b;
printf("addition=%d",c);
getch();
}
9. Subtract of two numbers without using subtraction operator
#include<stdio.h>
int main(){
int a,b,sum;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
sum = a + ~b + 1;
printf("\nDifference of two integers: %d",sum);
return 0;
}
Output:-
10. Find square root of number example
#include<stdio.h>
#include<math.h>
int main(){
int num;
printf("Enter an integer number: ");
scanf("%d",&num);
printf("\nSquare root: %f",sqrt(num));
return 0;
}
Output:-
11. Find area of circle using #define
#include<stdio.h>
#include<conio.h>
#define PI 3.142
void main()
{
float r,a;
clrscr();
printf("enter the radius:");
scanf("%f",&r);
a=PI*r*r;
printf("\nArea of Circle is: %.2f\n",a);
getch();
}
Output:-
12. Program to find gross salary.
#include<stdio.h>
void main()
{
int gs,bs,da,ta;
printf("Enter basic salary:");
scanf("%d",&bs);
da=(10*bs)/100;
ta=(12*bs)/100;
gs=bs+da+ta;
printf("gross salary=%d",gs);
}
Output:
13. Find volume of cube
#include<stdio.h>
#include<conio.h>
{
int l,b,h,v;
clrscr();
printf("enter the value of l:\n");
scanf("%d",&l);
printf("enter the value of b:\n");
scanf("%d",&b);
printf("enter the value of h:\n");
scanf("%d",&h);
v=l*b*h;
printf("Volume Of Cube::%d",v);
getch();
}
Output:-
enter the value of l: 10
enter the value of b: 10
enter the value of h: 10
volume of Cube:1000
---------------------------------------------------------------------
14. Find months and remaining day from total days
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,r;
clrscr();
printf("enter the value a:\n");
scanf("%d",&a);
b=a/30;
printf("Month::%d\n",b);
r=a%30;
printf("Remaining Days::%d",r);
getch();
}
Output:-
enter the value a:71
Month=2
Remaining Days=11
---------------------------------------------------------------------
15. Find simple interest
#include<stdio.h>
#include<conio.h>
void main()
{
float i,p,r,n;
clrscr();
printf("enter the value p:");
scanf("%f",&p);
printf("enter the value r:");
scanf("%f",&r);
printf("enter the value n:");
scanf("%f",&n);
i=(p*r*n)/100;
printf("\nInterest=%f",i);
getch();
}
Output:-
16. Find differenciate in rupees and paisa
#include<stdio.h>
#include<conio.h>
void main()
{
int r,p;
float a;
clrscr();
printf("enter the value a:\n");
scanf("%f",&a);
r=a;
printf("\nTotal Rupees:%d\n",r);
p=(a-r)*100;
printf("\nTotal Paisa:%d\n",p);
getch();
}
Output:-
enter the value a:9.50
Total Rupees:9
Total Paisa:50
---------------------------------------------------------------------
17. Swapping of two number using third variable
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("\nEnter the value of A\n");
scanf("%d",&a);
printf("\nEnter the value of B\n");
scanf("%d",&b);
clrscr();
printf("\nBefore swapping\n");
printf("A::%d\nB::%d",a,b);
temp=a;
a=b;
b=temp;
printf("\nAfter swapping\n");
printf("A::%d\nB::%d",a,b);
getch();
}
Output:-
Enter the value of A: 15
Enter the value of B: 20
Before swapping
A::15
B::20
After swapping
A::20
B::15
--------------------------------------------------------------------
18. Swapping of two number without third variable
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nEnter the value of A\n");
scanf("%d",&a);
printf("\nEnter the value of B\n");
scanf("%d",&b);
clrscr();
printf("\nBefore swapping\n");
printf("A::%d\nB::%d",a,b);
a=b+a;
b=a-b;
a=a-b;
/* or directly use this another method
* a=a+b-(b=a);
*/
printf("\nAfter swapping\n");
printf("A::%d\nB::%d",a,b);
getch();
}
Output:-
Enter the value of A: 15
Enter the value of B: 20
Before swapping
A::15
B::20
After swapping
A::20
B::15
19. Example show use of getchar
#include<stdio.h>
#include<conio.h>
void main()
{
char a,b;
clrscr();
printf("\nEnter one character:");
scanf("%c",&a);
printf("Input character is ==> %c",a);
fflush(stdin);//to clear input buffer
printf("\n\n\nEnter second character:");
b=getchar();
printf("\nASCII value of character(%c)is=> %d",b,b);
getch();
}
Output:
Enter one character: p
Input character is ==> p
Enter second character: n
ASCII value of character(n)is=> 110
20. Example show Use of Putchar
#include<stdio.h>
#include<conio.h>
void main()
{
char a,b;
clrscr();
printf("\nEnter one lowercase character\n");
a=getchar();
printf("Lowercase character is ==>");
putchar(a);
printf("\n\nCharacter in uppercase ==>");
putchar(a-32);
getch();
}
Output:
Enter one lowercase character: g
Lowercase character is ==>g
Character in uppercase ==>G
21. Example show Use of getche
#include<stdio.h>
#include<conio.h>
void main()
{
char a,b;
clrscr();
printf("\nEnter first character: ");
a=getche();
printf("\nSecond character: ");
b=getche();
printf("\n\nFirst Character==> %c\nSecond Character==>%c",a,b);
getch();
}
Output:
Enter first character: D
Second character: S
First Character==> D
Second Character==>S
22. Program to convert temperature from degree centigrade to Fahrenheit.
#include<stdio.h>
int main() {
float celsius, fahrenheit;
printf("Enter temp in Celsius : ");
scanf("%f", &celsius);
fahrenheit = (1.8 * celsius) + 32;
printf("\nTemperature in Fahrenheit : %f\n ", fahrenheit);
return (0);
}
Output:-
23. Program to read total seconds and convert it into hour, min and sec
#include<stdio.h>
void main()
{
int ts,h,m,s;
printf(" Enter total sec: ");
scanf("%d",&ts);
h=ts/3600;
ts=ts%3600;
m=ts/60;
s=ts%60;
printf("hour = %d min = %d, sec= %d",h,m,s);
}
Output:
Enter total sec: 3690
hour = 1 min = 1, sec= 30
0 Comments