PPS Set-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Write a C-Program for Fibonacci Series:

#include<stdio.h>
void main()
{
int n,i,a=0,b=1,c;
printf("Fibonacci Series\n");
printf("Enter the number of terms of the series\n");
scanf("%d",&n);
printf("%d\t%d",a,b);
for(i=2;i<n;i++)
{
c=a+b;
printf("\t%d",c);
a=b;
b=c;
}
}

1
Write a C-Program to check whether a given number is Palindrome (or)
Not:
#include<stdio.h>
void main()
{
int n,rev=0,rem,temp;
printf("Enter the Number\n");
scanf("%d",&n);
temp=n;
while(n!=0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
if(temp==rev)
printf("Entered number is a Palindrome");
else
printf("Entered number is not a Palindrome");
}

2
Write a C-Program to print Prime Numbers from 1 to n:
#include<stdio.h>
void main()
{
int n,i,fact,j;
printf("Enter the number\n");
scanf("%d",&n);
printf("Prime Numbers are:\n");
for(i=1;i<=n;i++)
{

fact=0;
for(j=1;j<=n;j++)
{
if(i%j==0)
fact++;
}
if(fact==2)
printf("%d\t",i);
}
}

3
Write a C-Program to find the Sum of digits of a given positive integer:
#include<stdio.h>
void main()
{
int n,sum=0,rem;
printf("Enter the number\n");
scanf("%d",&n);
while(n!=0)
{
rem=n%10;
sum=sum+rem;
n=n/10;
}
printf("sum of digits is:%d ",sum);
}

4
Write a C-Program to check whether a given number is Armstrong (or)
not:
#include<stdio.h>
void main()
{
int n,sum=0,rem,temp;
printf("Enter the number\n");
scanf("%d",&n);
temp=n;
while(n!=0)
{
rem=n%10;
sum=sum+rem*rem*rem;
n=n/10;
}
if(temp==sum)
printf("The Entered number is Armstrong\n");
else
printf("The Entered number is not Armstrong\n");
}

5
Write a C-Program to find the Factorial of a given number:
#include<stdio.h>
void main()
{
int i,n;
printf("Enter the value\n");
scanf("%d",&n);
for(i=1;n!=0;n--)
{
i=n*i;
}
printf("Factorial of entered number is %d\n",i);
}

6
Write a C-Program to print the Multiplication Table of a given number:
#include<stdio.h>
void main()
{
int i,a,b;
printf("Tables\n");
printf("Enter the value of table to be printed\n");
scanf("%d",&a);
for(i=1;i<=10;i++)
{
b=a*i;
printf("%d*%d=%d\n",a,i,b);
}
}

7
Write a C-Program on Switch Case:
#include<stdio.h>
void main()
{
int a,b,ch;
float c;
printf("Enter the values of any two numbers\n");
scanf("%d%d",&a,&b);
printf("1.Addition\n");
printf("2.Subtraction\n");
printf("3.Multiplication\n");
printf("4.Division\n");
printf("Enter your choice\n");
scanf("%d",ch);
switch(ch)
{
case 1:
c=a+b;
printf("The sum is %d\n",c);
break;
case 2:
c=a-b;
printf("The difference is %d\n",c);
break;
case 3:
c=a*b;
printf("The product is %d\n",c);
break;
case 4:
c=a/b;
printf("The quotient is %d\n",c);
break;

8
default:
printf("Invalid Option\n");
}
}

9
Write a C-Program to find Roots of the quadratic equation:
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c,d;
float r1,r2;
printf("Enter the co-efficients of the equation\n");
scanf("%d%d%d",&a,&b,&c);
d=b*b-4*a*c;
r1=-b+sqrt(d)/(2*a);
r2=-b-sqrt(d)/(2*a);
if(d>0)
{
printf("The Roots are real and distinct\n");
printf("Root-1=%f,Root-2=%f\n",r1,r2);
}
else if(d==0)
{
printf("The Roots are real and equal\n");
printf("Root-1=%f,Root-2=%f\n",r1,r2);
}
else
{
printf("The roots are imaginary\n");
}

10
Write C-programs to print Pyramid patterns:
Pattern-1:
#include<stdio.h>
void main()
{
int i,j,n;
printf("Pattern 1\n");
printf("Enter the value of n\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d\t",i);
}
printf("\n");
}
}

Output:
1
2 2
3 3 3
4 4 4 4 …………etc.

11
Pattern-2:
#include<stdio.h>
void main()
{
int i,j,n;
printf("Pattern 1\n");
printf("Enter the value of n\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d\t",j);
}
printf("\n");
}
}

Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5 …………etc.

12
Pattern-3:
#include<stdio.h>
void main()
{
int i,j,n,k=1;
printf("Pattern 1\n");
printf("Enter the value of n\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d\t",k);
k++;
}
printf("\n");
}
}

Output:
1
2 3
4 5 6
7 8 9 10 …………..etc.

13

You might also like