Sunteți pe pagina 1din 10

Ex.

No: 8

Date:

FINDING THE GREATEST NUMBER

AIM:

To Write program to find the greatest among three numbers.

ALGORITHM:

Step1: Start the program

Step2: Get the values of a,b,c as input.

Step3: Compare the a,b,c and find the greatest of three numbers.

Step4: Print the greatest number.

Step5: Print the greatest number.

Step6: End the program.


PROGRAM:

/* Program to find the Greatest of Three numbers */

#include<stdio.h>

#include<conio.h>

Void main()

int a, b,c;

int great;

clrscr();

printf(“Enter a,b,c:”);

scanf(“%d%d%d”,&a,&b,&c);

if(a>b)

if(a>c) great=a;

else great=c;

else

if(b>c) great=b;

else great=c;

printf(“The greatest number is: %d”,great);

getch();

}
OUTPUT:

Enter a,b,c: 10 20 30

The greatest number is : 30

RESULT:

Thus the greatest among three numbers was executed and the result verified.
Ex. No: 9

Date:

PRIME OR NOT

AIM:

To write a program to check if the given number is prime or not.

ALGORITHM:

Step 1: Start the program

Step 2: Get the number ‘n’ as input.

Step 3: If any number between 2 to n-1 divides the number n then print ‘not a prime number’,
else print ‘prime number’.

Step 4: End the program.


PROGRAM:

/* Program to find the Prime or Not */

#include<stdio.h>

#include<conio.h>

Void main()

int n,i;

int i.sprime=1;

clrscr();

Printf(“Enter the number:”);

Scanf(“%d”,&n)

for(i=2;i<=n-1;i++)

if((n%i)==0) isprime=0;

if(isprime==1)

printf(“%d is prime.”,n);

else

printf(“%d is NOT prime.”,n);

getch();

}
OUTPUT:

Run 1:

Enter the number: 8

8 is NOT prime.

Run 2:

Enter the number: 7

7 is prime.

RESULT:

Thus a program to check whether the given number is prime or not was
executed and the result verified.
Ex. No: 10

Date:

AVERAGE OF ‘N’ NUMBERS

AIM:

To write a program to find the sum and average of the given ‘N’ numbers.

ALGORITHM:

Step 1: Start the program

Step 2: Get the number of numbers ‘n’ as input.

Step 3: Get the numbers into the array a[i].

Step 4: Add their sum into the variable sum.

Step 5: Find average as avg= (sum/n).

Step 6: print sum, average.

Step 7: End the program.


PROGRAM:

/* Program to find the average of n numbers */

#include<stdio.h>

#include<<conio.h>

void main()

int I,n,sum=0, a[30];

float avg;

clrscr();

printf(“Enter the number of numbers:\n”);

scanf(“%d”,&n);

printf(“Eter the numbers:\n”);

for(i=0;i<n;i++)

scanf(“%d”,&a[i]);

sum+=a[i]

printf(“The sum of given %d numbers is %d\n”,n,sum);


avg=(float)sum/n;

printf(“The Average of given %d numbers is %f”, n,avg);

getch();

OUTPUT:

Enter the number of numbers: 3

Enter the numbers: 1 2 3

The sum of given 3 numbers is 6

The average of given numbers is 2.000000

RESULT:
Thus a program to find the sum and average of given N umbers executed and the
result verified.

S-ar putea să vă placă și