Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

TABLE OF CONTENTS

S.No. NAME OF PROGRAMME SIGNATURE


//1.a A programme to swap two numbers entered by user using two variables.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b; //Declaration of variables
clrscr(); //To clear the previous output screen
printf("Enter two numbers:");
printf("\na="); //To print on output screen
scanf("%d",&a); //To take input from user
printf("\nb=");
scanf("%d",&b);
b=a-b;
a=a-b;
b=a+b;
printf("Swapped numbers are:");
printf("\na=%d",a);
printf("\nb=%d",b);
getch();
}
//OUTPUT
Enter two numbers:
a=12
b=21
Swapped numbers are:
a=21
b=12
//1.b A programme to swap two numbers entered by user using three variables.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp; //Declaration of variables
clrscr(); //To clear the previous output screen
printf("Enter two numbers:"); //To print on the output screen
printf("\na=");
scanf("%d",&a); //To take input from user
printf("\nb=");
scanf("%d",&b);
temp=a;
a=b;
b=temp;
printf("Swapped numbers are:");
printf("\na=%d",a);
printf("\nb=%d",b);
getch();
}

//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

You might also like