Ex No: 7a Date: Print All Combinations of A Four Digit Number
Ex No: 7a Date: Print All Combinations of A Four Digit Number
Date:
PRINT ALL COMBINATIONS OF A FOUR DIGIT NUMBER
Program:
#include<stdio.h>
int main()
{
int i1=0,i2=0,i3=0,n;
printf("\nenter a value for n");
scanf("%d",&n);
for(i1=1;i1<=n;i1++)
{
for(i2=1;i2<=n;i2++)
{
for(i3=1;i3<=n;i3++)
{
if(i1!=i2&&i2!=i3&&i1!=i3)
{
printf("%d%d%d\n",i1,i2,i3);
}
}
}
}
return 0;
}
Output :
Enter the values: 1 2 3 4
Output:
1234
1243
1324
1342
1423
1432
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
3412
3421
4123
4132
4213
4231
4312
4321
RESULT:
The program has been sucessfuly excecuted
Ex no: 7b
Date:
Sine series
Aim: To write a C program to generate the Sine series: S=x - x3 /3! + x5 /5! - x7 /7! +
Xn /n!
Algorithm :
1.Get the values of x and n where n decides how long the series should continue.
2.Set the initial conditions S=x, term=x , i=1
3.To get the terms with alternate sign repeatedly execute sign=-sign
4.Till the desired no of terms are generated repeat the following steps
a. Identify the current I th term
b. Generate current term from its predecessor.
i*(i-1)
c. Add current term with the appropriate sign to the accumulated sum for the sine
function
i=i+2 term=-term* x2 / i*(i-1) S=S+ term
Program:
#include<stdio.h>
main()
{
int i=1,n;
float sum, term, x;
printf(enter the value of x in radians\t);
scanf(%f,&x);
printf(\n enter the prower of end term\t);
scanf(%d,&n);
sum=0;
term=x;
I=1;
while(i<=n)
{
sum=sum+term;
term=(term*x*x-1)/(i+1)*(i+2);
I=i+2;
}
printf(sin of %42f is %f,x,sum);
}
Sine Series
Input:.
Enter the values of x and n
1
2
Output
0.8333333.
RESULT:
The program has been sucessfuly excecuted.
Ex no: 7c
Date:
Prime Number Checking
Program:
#include<stdio.h>
int main()
{
int n, d=2, count=0;
int mul=0;
printf("Enter the Number n:");
scanf("%d",&n);
for(;d<n;d++)
{
if(d<n)
{ mul=n%d;
if(mul==0)
count++;
}
}
if(count==0)
{
printf("Number is Prime");
}
else
{
printf("Not Prime");
}
return 0;}
Output:
Enter a number : 11
11 is a prime number .
Enter a number : 10
10 is not a prime number.
Ex no: 7d
Date:
Prime Number Generation
PROGRAM:
#include<stdio.h>
int main()
{
int n;
int i, j;
printf("Enter the Number:");
scanf("%d",&n);
printf("2");
for(i=3;i<n;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
{
printf("%d",i);
}
else
{
printf(" ");
}
}
}
return 0;}
Output:
Enter the Limit value : 10
2
3
5
7
RESULT:
The program has been successfully excecuted.