Exercise - 7
Exercise - 7
Exercise - 7
FIBONACCI SERIES:
#include <stdio.h>
int main() {
int i,n,c,a,b;
a=0,b=1;
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;
scanf("%d",&n);
for(i=1;n>0;n=n/10)
a=n%10;
b=b*10+a;
return 0;
}
PALINDROME or NOT:
#include <stdio.h>
int main() {
int i,n,a,b=0,d;
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
return 0;
}
SUM OF THE DIGITS:
#include <stdio.h>
int main() {
int i,n,s,t,a;
scanf("%d",&n);
for(i=0;n>0;i++)
t=n%10;
n=n/10;
a=a+t;
return 0;
}
PRODUCT OF THE DIGITS:
#include <stdio.h>
int main() {
int i,n,s,t,a=1;
scanf("%d",&n);
for(i=0;n>0;i++)
t=n%10;
n=n/10;
a=a*t;
return 0;
}
RIGHT ANGLE TRIANGLE USING ASTRICK:
#include <stdio.h>
int main() {
int i,j,n;
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;
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;
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;
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;
scanf("%d",&n);
r=n;
for(i=0;n!=0;n=n/10)
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)
else
return 0;