Exercise - 7

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

EXERCISE – 7

FIBONACCI SERIES:
#include <stdio.h>

int main() {

int i,n,c,a,b;

a=0,b=1;

printf("Upto Value: ");

scanf("%d",&n);

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

printf("%d\n",a);

c=a+b;

a=b;

b=c;

return 0;

}
REVERSE NUMBERS:
#include <stdio.h>

int main() {

int i,n,a,b=0;

printf("Enter the Number: ");

scanf("%d",&n);

for(i=1;n>0;n=n/10)

a=n%10;

b=b*10+a;

printf("Reversed number is %d",b);

return 0;

}
PALINDROME or NOT:
#include <stdio.h>

int main() {

int i,n,a,b=0,d;

printf("Enter the Number: ");

scanf("%d",&n);

d=n;

for(i=1;n>0;n=n/10)

a=n%10;

b=b*10+a;

if(d==b)

printf("%d is a Palindrome",d);

else

printf("%d is not a Palindrome",d);

return 0;

}
SUM OF THE DIGITS:
#include <stdio.h>

int main() {

int i,n,s,t,a;

printf("Enter the value: ");

scanf("%d",&n);

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

t=n%10;

n=n/10;

a=a+t;

printf("Sum of the digits is %d",a);

return 0;

}
PRODUCT OF THE DIGITS:
#include <stdio.h>

int main() {

int i,n,s,t,a=1;

printf("Enter the value: ");

scanf("%d",&n);

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

t=n%10;

n=n/10;

a=a*t;

printf("Product of the digits is %d",a);

return 0;

}
RIGHT ANGLE TRIANGLE USING ASTRICK:
#include <stdio.h>

int main() {

int i,j,n;

printf("Enter the value: ");

scanf("%d",&n);

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

for(j=1;j<=i;j++)

printf("*");

printf("\n");

return 0;

}
RIGHT ANGLE TRIANGLE USING NUMBERS:
#include <stdio.h>

int main() {

int i,j,n;

printf("Enter the value: ");

scanf("%d",&n);

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

for(j=1;j<=i;j++)

printf("%d",j);

printf("\n");

return 0;

}
RIGHT ANGLE TRIANGLE USING SAME NUMBERS:
#include <stdio.h>

int main() {

int i,j,n;

printf("Enter the value: ");

scanf("%d",&n);

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

for(j=1;j<=i;j++)

printf("%d",i);

printf("\n");

return 0;

}
PYRAMID:
#include <stdio.h>

int main() {

int n,i,j,k;

printf("Enter Range: ");

scanf("%d",&n);

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

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

printf(" ");

for(k=1;k<=i;k++)

printf("* ");

printf("\n");

return 0;

}
ARMSTRONG NUMBER:
#include <stdio.h>

int main() {

int i,r,n,re,rs=0;

printf("Enter the number: ");

scanf("%d",&n);

r=n;

for(i=0;n!=0;n=n/10)

i++;

printf("Number of digits is %d\n",i);

n=r;

for(i=i;n>0;n=n/10)

re=n%10;

rs=pow(re,i)+rs;

printf("Answer is %d\n",rs);

if(r==rs)

printf("It is Armstrong Number");

else

printf("It is not a Armstrong Number");

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy