Date: Find The Factorial of Given Number Using Any Loop.: EX - NO:6 (I)
Date: Find The Factorial of Given Number Using Any Loop.: EX - NO:6 (I)
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:
#include <stdio.h>
Void main()
{
int i,f=1,num;
for(i=1;i<=num;i++)
{
f=f*i;
}
printf("The Factorial of %d is: %d\n",num,f);
}
Output:
Result:
Aim:
To Write a C program to find the given number is a prime or not
Algorithm:
#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:
Aim:
To write C Program to compute sine and cos series.
Algorithm:
#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:
#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:
Aim:
To Write a C program to construct a pyramid of numbers.
Algorithm:
#include <stdio.h>
#include<conio.h>
int main()
{
int rows, space, i, j;
clrscr();
printf("Enter number of rows: ");
scanf("%d",&rows);
printf("%2d",abs(j));
}
printf("\n");
}
}
Output:
Result: