1. Write a program to print “Hello World” message.
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr(); // clears the output window
printf("\n \"Hello World\""); // prints the message
getch();
return 0;
}
Output:
“Hello World”
2. Write a program to print Name , Address and Birth Date.
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr(); // clears the output window
printf("\n Name : Diz"); // prints the name
printf("\n Address : Navsari"); // prints the address
printf("\n Birth Date : 31-03-1989"); // prints the birth date
getch();
return 0;
}
Output:
Name: Diz
Address: Navsari
Birth Date:31-03-1989
3. Write a program to add, multiply and divide two integers and float numbers.
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y; // define 2 integer variable x & y
float a,b; // define 2 real variable x & y
clrscr(); // clears the output window
printf("\n Arithmetic operation on integer:-");
printf("\n\n Enter 1st integer number : ");
scanf("%d",&x); // input first integer number
printf(" Enter 2nd integer number : ");
scanf("%d",&y); // input second integer number
printf("\n\n Addition of two integer numbers is : %d",x+y);
printf("\n Multiplication of two integer numbers is : %d",x*y);
printf("\n Division of two integers numbers is : %d",x/y);
printf("\n\n Arithmetic operation on float:-");
printf("\n\n Enter 1st float number : ");
scanf("%f",&a); // input first real number
printf(" Enter 2nd float number : ");
scanf("%f",&b); // input second real number
printf("\n\n Addition of two float number is :%.2f",a+b);
printf("\n Multiplication of two float number is :%.2f",a*b);
printf("\n Division of two float number is:%.2f",a/b);
getch();
return 0;
}
Output:
Arithmetic operation on integer:-
Enter 1st integer number : 20
Enter 2nd integer number : 5
Addition of two integer numbers is : 25
Multiplication of two integer numbers is : 100
Division of two Integers numbers is : 4
Arithmetic operation on float:-
Enter 1st float number : 10.50
Enter 2nd float number : 5.2
Addition of two float number is : 15.70
Multiplication of two float number is : 54.60
Division of two float number is: 2.02
4. Write a program to convert Rupees(float) to paisa(int).
#include<stdio.h>
#include<conio.h>
int main()
{
float rs; //real variable for rupees
int ps; // integer variable for paisa
clrscr();
printf("\n\n Enter rupees to convert into paisa : ");
scanf("%f",&rs);
ps=rs*100;
printf("\n Paisa of given rupees is %d",ps);
getch();
return 0;
}
Output:
Enter rupees to convert into paisa : 98.52
Paisa of given rupees is 9852
5. Write a program to accept number of days and print year, month and remaining days.
#include<stdio.h>
#include<conio.h>
int main()
{
int day,y,m; /*day for day input & output,
y for calculate year,
m for calculate month*/
printf("Enter the number of days : ");
scanf("%d",&day);
y=day/365; //calculate years
day%=365; // calculate remaining days
m=day/30; // calculate months
day%=30; // calculate remaining days
printf("%d years,%d months, %d days",y,m,day);
getch();
return 0;
}
Output:
Enter number of days : 1025
2 years,9 months, 25 days
6. Write a program to check whether the entered number is prime or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,flag=0; // declare variable i, n & flag and initialize flag with 0
clrscr();
printf("\n Enter the number : ");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("\n %d is a Prime number",n);
}
else
{
printf("\n %d ia not a Prime number",n);
}
getch();
return 0;
}
Output:
Enter the number : 4
4 is not a Prime number
Enter Number : 7
7 is a Prime number
7. Write a program to check whether the entered number is even or odd.
#include<stdio.h>
#include<conio.h>
int main()
{
int n; // declare integer type variable
clrscr();
printf("\n Enter the number : ");
scanf("%d",&n);
if(n%2==0) // check the condition whether the modulo is zero or not
{
printf("\n Entered number %d is EVEN",n);
}
else // otherwise this part will be executes
{
printf("\n Entered number %d is ODD",n);
}
getch();
return 0;
}
Output:
Enter the number : 1
Entered number 1 is ODD
Enter the number : 2
Entered number 2 is EVEN
8. Using While loop print 1 2 3 4 5 …..10.
#include<stdio.h>
#include<conio.h>
int main()
{
int n=1;
clrscr();
while(n<=10) // loop will be executed till n is less or equl to 10
{
printf(" %d ",n);
n++;
}
getch();
return 0;
}
Output:
1 2 3 4 5 6 7 8 9 10
9. Print series 2, 4, 6, 8,…….n.
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n; // declare two integer type variables
clrscr(); // clears the output window
printf("\n Enter the number : ");
scanf("%d",&n); // input the value of n
printf(“\n”); // will break the line on output window
for(i=2;i<=n;i++)
{
if(i%2==0)
{
printf(" %d ",i);
}
}
getch();
return 0;
}
Output:
Enter the number : 14
2 4 6 8 10 12 14
10. Print series 2, 4, 16,……n*n using shorthand operator and while loop
#include<stdio.h>
#include<conio.h>
int main()
{
int n,x; // declare the variable
long double i=2; //declare the variable of long double type
clrscr();
printf("Enter the number : ");
scanf("%d",&n);
printf("\n");
x=1;
while(x<=n) // loop will be execute till the value of x I less or equal n
{
printf("%.2Lf\n",i); // print the value of I upto 2 decimals only
x++;
i*=i;
}
getch();
return 0;
}
Output:
Enter the number : 4
2.00
4.00
16.00
256.00