Você está na página 1de 7

SUM OF TWO NUMBERS

Aim:
To write a C program to get the sum of two number.
Algorithm:
Step 1: Start the program.
Step 2: Read the two variables a,b.
Step 3: Sum of a and b (c=a+b).
Step 4: Start the result.
Step 5: Stop the program.
Program Coding:
#include<stdio.h>
#include<conio.h>
Void main()
{
int a,b,c;
Clrscr();
Printf(enter the two numbers);
Scanf(%d %d,&a,&b);
C=a+b;
Printf(the answer is %d,c);
getch();
}
Result:
Thus the C program was created and output is successfully verified.

ODD OR EVEN NUMBERS


Aim:
To write a C program the given number is odd or even.
Algorithm:
Step 1: Start the program.
Step 2: Read the variable a.
Step 3: Check (a%<==0) is true then the number is even.
Step 4: Otherwise the number is odd.
Step 5: Stop the program.
Program Coding:
#include<stdio.h>
#include<conio.h>
Void main()
{
int a;
Clrscr();
Printf (Enter the value of a);
scanf(%d %d,&a);
If(a%2==0)
Printf (The number is even);
else
Printf (The number is odd);
getch();
}
Result:
Thus the C program was created and output is successfully verified.

GREATEST OF THREE NUMBERS


Aim:
To write a C program check whether the greatest of three numbers.
Algorithm:
Step 1: Start the program.
Step 2: Read the variables a,b,c.
Step 3: Check((a>b)&&(a>c)) is true point a is greater.
Step 4: Otherwise check(b>c) is true point B is greater
Step 5:otherwise c is greater..
Step 6: Stop the program.
Program Coding:
#include<stdio.h>
#include<conio.h>
Void main()
{
int a,b,c;
Clrscr();
Printf(enter the three numbers);
Scanf(%d %d %d,&a,&b,&c);
if((a>b)&&(a>c))
{
Printf(a is greater);
}
else if(b>c)
{
Printf(b is greater);
}
else
{

Printf(c is greater);
}
getch();
}
Result:
Thus the C program was created and output is successfully verified.

SWAPPING TWO NUMBERS USING WITHOUT TEMPORARY VARIABLE


Aim:
Write a C program to swapping the two number without using temporary variable.
Algorithm:
Step 1: Start the program.
Step 2: Read the given variables .
Step 3: Assign without temporary variable as t, as b.
Step 4: perform the number before swapping without temporary variable.
Step 5:perform the number after swapping using without temporary variable.
Step 6: print the result.
Step 5: Stop the program.
Program Coding:
#include<stdio.h>
#include<conio.h>
Void main()
{
int a,b;
Clrscr();
Printf(enter the two numbers);
Scanf(%d %d,&a,&b);

Printf(before swapping: %d %d,a,b);


b=a+b;
a=b-a;
b=b-a;
printf(After swapping:%d%d,a,b);
getch();
}
Result:
Thus the C program was created and output is successfully verified.

SWAPPING TWO NUMBERS USING WITH TEMPORARY VARIABLE


Aim:
Write a C program swapping the two number using temporary variable.
Algorithm:
Step 1: Start the program.
Step 2: Read the given variable.
Step 3: Assign temporary variable as t.
. Step 4: perform the number before swapping without temporary variable.
Step 5:perform the number after swapping using without temporary variable.
Step 6:print the result.
Step 7: Stop the program.
Program Coding:
#include<stdio.h>
#include<conio.h>
Void main()
{
int a,b,t;
Clrscr();

Printf(enter the two numbers);


Scanf(%d %d,&a,&b);
Printf(Before swapping %d %d,a,b);
t=a;
a=b;
b=t;
printf(After swapping %d %d,a,b);
getch();
}
Result:
Thus the C program was created and output is successfully verified
FIBONACCI SERIES
Aim:
Write a C program to find a fibonacci series.
Algorithm:
Step 1: Start the program.
Step 2: Read the terms.
Step 3: check terms it is Fibonacci series.
Step 4: terms are Fibonacci series.
Step 5: Stop the program.
Program Coding:
#include<stdio.h>
#include<conio.h>
Void main()
{
Int n,a=0,b=1,next,c;
Clrscr();

Printf(enter the no of term \n);


Scanf(%d,&n);
Printf(First %d term of Fibonacci series are :\n);
for(c=0;c<n;c++)
{
if(c<=1)
{
next=c;
}
else
{
next=a+b;
a=b;
b=next;
}
Printf(%d\n,next);
}
getch();
}
Result:
Thus the C program was created and output is successfully verified.

Você também pode gostar