Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

Aim:- to write a program find the sum of three numbers

Program Description:-
In this program , we accept three numbers and find their sum.
Source Code:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,sum;
clrscr();
printf("\nEnter three numbers :");
scanf("%d%d%d",&a,&b,&c);
sum=a+b+c;
printf("\n Sum of %3d,%3d and %3d is=%4d",a,b,c,sum);
getch();
}
Input:-
Enter three numbers :24 32 65
Output:-
Sum of 24, 32 and 65 is= 121
Aim:- to write program to exchange of two numbers
Program Description:-
In this program we exchange two numbers without using the third variable. The process can be performed by using
the third variable also.
Source Code:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nEnter two numbers :");
scanf("%d%d",&a,&b);
printf("\n Before swapping, values are a=%3d and b=%3d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\n After swapping, values are a=%3d and b=%3d",a,b);
getch();
}
Input:-
Enter two numbers :7 9
Output:-
Before swapping, values are a=7 and b=9
After swapping, values are a=9 and b=7
Source Code :-
#include<stdio.h>
#include<conio.h>
void main()
{
int n,f=1,i=1;
clrscr();
printf("\n Enter a number:");
scanf("%d",&n);
while(i<=n)
{
f*=i;
i++;
}
printf("Factorial of %3d is = %5d",n,f);
getch();
}
Input
Enter a number:6
Output
Factorial of 6 is = 720
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,k=0;
clrscr();
printf("\n Enter a number :");
scanf("%d",&n);
i=1;
while(i<=n)
{
if(n%i==0)
k++;
i++;
}
if(k==2)
printf("\n Given number is a prime number");
else
printf("\n Given number is not a prime number");
}
Input:
Enter a number : 6
Output:
Given number is not a prime number
Input:
Enter a number :11
Output:
Given number is a prime number

You might also like