0% found this document useful (0 votes)
50 views15 pages

Date: Find The Factorial of Given Number Using Any Loop.: EX - NO:6 (I)

C program

Uploaded by

Kumar Rani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views15 pages

Date: Find The Factorial of Given Number Using Any Loop.: EX - NO:6 (I)

C program

Uploaded by

Kumar Rani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

EX.

NO:6(i)
Find the factorial of given number using any loop.
Date:

Aim:
To Write a C program to find the factorial of given number using any loop.
Algorithm:

1. Start the program.

2. Declare the variables.

3. Get the value of the variables from the user.

4. Find the factorial of given number using for loop.

5. Print the result.

6. Stop the program.


Program:

#include <stdio.h>
Void main()
{
int i,f=1,num;

printf("Enter a number to find factorial: ");


scanf("%d",&num);

for(i=1;i<=num;i++)
{
f=f*i;
}
printf("The Factorial of %d is: %d\n",num,f);
}
Output:

Result:

Thus the program was compiled and executed successfully


EX.NO:6(ii)
Find the given number is a prime or not
Date:

Aim:
To Write a C program to find the given number is a prime or not

Algorithm:

1. Start the program.


2. Take num as input.
3. Initialize a variable temp to 0.
4. Iterate a “for” loop from 2 to num/2.
5. If num is divisible by loop iterate, then increment temp.
6. If the temp is equal to 0,
7. Return “Num IS PRIME”.
8. Else,
9. Return “Num IS NOT PRIME”.

10. Print the result.

11. Stop the program


Program:

#include <stdio.h>
int main()
{
int i, num, temp = 0;
printf("Enter any number to Check for Prime: ");
scanf("%d", &num);
for (i = 2; i <= num / 2; i++)
{
if (num % i == 0)
{
temp++;
break;
}
}
if (temp == 0 && num != 1)
{
printf("%d is a Prime number", num);
}
else
{
printf("%d is not a Prime number", num);
}
return 0;
}
Output:

Result:

Thus the program was compiled and executed successfully


EX.NO:6(iii)
Compute sine and cos series
Date:

Aim:
To write C Program to compute sine and cos series.

Algorithm:

1. Start the program.

2. Declare the variables.

3. Get the value of the variables from the user.

4. Compute sine and cos series.

5. Print the result.

6. Stop the program.


Program:

#include<stdio.h>
#include <math.h>
#define PI 3.1416
#define MAX 150
main ( ){
int angle;
float x,y;
angle = 0;
printf("Angle sin(angle)");
while(angle <= MAX){
x = (PI/MAX)*angle;
y = sin(x);
printf("%15d %13.4f", angle, y);
angle = angle + 10;
}
printf("Angle cos(angle)");
while(angle <= MAX)
{
x = (PI/MAX)*angle;
y = cos(x);
printf("%15d %13.4f", angle, y);
angle = angle + 10;
}
}
Output:

Result:
Thus the program was compiled and executed successfully
EX.NO:6(iv)
Checking a number palindrome
Date:

Aim:
To Write a C program to Checking a number palindrome.

Algorithm:

1. Start the program.


2. Declare the variables.
3. Get the number from user
4. Hold the number in temporary variable
5. Reverse the number
6. Compare the temporary number with reversed number
7. If both numbers are same, print palindrome number
8. Else print not palindrome number
9. Print the result.
10. Stop the program.
Program:

#include<stdio.h>
int main()
{
int n,r,sum=0,temp;
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
printf("palindrome number ");
else
printf("not palindrome");
return 0;
}
Output:

Result:

Thus the program was compiled and executed successfully


EX.NO:6(v)
Construct a pyramid of numbers.
Date:

Aim:
To Write a C program to construct a pyramid of numbers.

Algorithm:

1. Start the program.

2. Declare the variables.

3. Get the input values from the user.

4. To construct a pyramid of numbers.

5. Print the result.

6. Stop the program.


Program:

#include <stdio.h>
#include<conio.h>
int main()
{
int rows, space, i, j;
clrscr();
printf("Enter number of rows: ");
scanf("%d",&rows);

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


{
for(space=1; space <= rows-i; space++)
printf(" ");

for(j=0-i; j <= i; j++)


{

printf("%2d",abs(j));
}
printf("\n");
}

}
Output:

Result:

Thus the program was compiled and executed successfully.

You might also like