Professional Documents
Culture Documents
S.No. Name of Programme Signature
S.No. Name of Programme Signature
//OUTPUT
Enter two numbers:
a= 23
b= 42
Swapped numbers are:
a= 42
b=23
//2. A programme to check whether the number entered by user is prime or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,i,temp=0; // Declaration of variable
clrscr(); // To clear the previous output screen
printf("Enter a number:"); //To print on the output screen
scanf("%d",&a); //To take input from user
for(i=2;i<=a/2;i++) //For loop header
{
if(a%2==0) //If condition
temp=1;
}
if(temp==0)
printf("\nNumber is prime.");
else
printf("\nNumber is not prime.");
getch();
}
//OUTPUT
Enter a number: 12
Number is not prime.
//3. A programme to find out factorial of a number entered by user.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,i; //Declaration of variables
clrscr(); // To clear the previous output screen
printf("Enter a number:"); //To print on the output screen
scanf("\n%d",&a); //To take input from user
for(i=a-1;i!=0;i--) //For loop header
{
a=a*i;
}
printf("\nFactorial of the number is:%d",a);
getch();
}
//OUTPUT
Enter a number: 4
Factorial of the number is: 12
//4. A programme to check whether a year entered by user is leap year or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int a; //Declaration of variables
clrscr(); //To clear the previous output screen
printf("Enter an year:"); //To print on the output screen
scanf("%d",&a); //To take input from user
if(a%4==0&&a%100==0&&a%400==0)
{
printf(“\nThis is a leap year”);
}
else if(a%4==0&&a%100!==0)
{
printf(“\nThis is a leap year”);
}
else
{
Printf(“\nThis is not a leap year”);
}
getch();
}
//OUTPUT
Enter an year: 2400
This is a leap year