0% found this document useful (0 votes)
33 views6 pages

S.No. Name of Programme Signature

This document contains: 1. An introduction to the table of contents and listing of 4 programs with their name and signatures. 2. Four code snippets that demonstrate: - Swapping two numbers using two and three variables - Checking if a number is prime - Calculating the factorial of a number - Determining if a year is a leap year 3. The output for each program is displayed below its code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views6 pages

S.No. Name of Programme Signature

This document contains: 1. An introduction to the table of contents and listing of 4 programs with their name and signatures. 2. Four code snippets that demonstrate: - Swapping two numbers using two and three variables - Checking if a number is prime - Calculating the factorial of a number - Determining if a year is a leap year 3. The output for each program is displayed below its code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy