CHAPTER : 6
Exercise
6.1:
#include<stdio.h>
void main()
{
int a,rev=10;
printf("Enter A 4 Digit Number To Reverse : \n");
scanf("%d", &a);
while(a>0)
{
printf("%d",(a%rev));
a/=10;
}
}
Exercise
6.2:
#include<stdio.h>
void main()
{
int a,fac=1;
printf("Enter a number : \n");
scanf("%d",&a);
while(a>0)
{
fac*=a;
a-=1;
}
printf("The factorial of the number is = %d", fac);
}
Exercise
6.3:
#include<stdio.h>
void main()
{
int a,ad,sum=0;
printf("Enter the number : \n");
scanf("%d",&a);
while(a>0)
{
ad=a%10;
sum+=ad;
a/=10;
}
printf("Sum of all digit is = %d",sum);
}
Exercise
6.4:
#include<stdio.h>
void main()
{
int
fbn,a=1,b=1,n,i=3;
printf("Enter the term of fibonacci number : \n");
scanf("%d", &n);
printf("%d %d ",a,b);
do
{
fbn=a+b;
printf("%d ",fbn);
b=a;
a=fbn;
i++;
}while(i<=n);
}
Exercise
6.5:
#include<stdio.h>
void main()
{
int a,rev=10;
printf("Enter A 4 Digit Number To Reverse : \n");
scanf("%d", &a);
for(;a>0;)
{
printf("%d",(a%rev));
a/=10;
}
}
Exercise
6.6:
#include<stdio.h>
#include<math.h>
void main()
{
float p,n,r,v;
loop:
{
printf("Enter value for 'P' 'R' 'N' : \n");
scanf("%f%f%f",&p,&r,&n);
v=p*(pow((1+r),n));
printf("\n\n\nP\tR\tN\t\tV\n%.1f\t%.1f\t%.1f\t\t%.1f\n\n",p,r,n,v);
goto
loop;
}
}
Exercise
6.7:(a)
#include<stdio.h>
void main()
{
int a,i;
for(a=1;a<=5;a++)
{
for(i=1;i<=a;i++)
{
printf("%d",a);
}
printf("\n");
}
}
Exercise
6.7:(b)
#include<stdio.h>
void main()
{
int i,j,limit;
printf("Enter limit: \n");
scanf("%d",&limit);
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf(" ");
}
for(j=5;j>=i;j--)
{
printf("*");
}
printf("\n");
}
}
Exercise
6.8
#include<stdio.h>
#define QNTT 5
void main()
{
int
age,cnt=0,cnt2=0,i;
for(i=1;i<=QNTT;i++)
{
printf("Enter the age :
Years old\b\b\b\b\b\b\b\b\b\b\b\b");
scanf("%d",&age);
if(age>60||age<50)
{
cnt2++;
continue;
}
cnt++;
}
printf("Total persons are %d\nAnd continued %d
times",cnt,cnt2);
}
Exercise
6.11
#include<stdio.h>
void main()
{
int
num,bin,base=1;
double fbin;
printf("Enter the number : \n");
scanf("%d",&num);
while(num>0)
{
bin=num%2;
fbin+=(bin*base);
base*=10;
num/=2;
}
printf("Binary form is %.0lf",fbin);
}
Exercise
6.12
#include<stdio.h>
#define r 15
#define c 18
void main()
{
int i,j,k;
for(i=1;i<4;i++)
{
for(j=0;j<c;j++)
{
printf("*");
}
printf("\n");
}
for(i=1;i<4;i++)
{
for(j=0;j<4;j++)
{
printf("*");
}
printf("\n");
}
for(i=1;i<4;i++)
{
for(j=0;j<c;j++)
{
printf("*");
}
printf("\n");
}
for(i=1;i<4;i++)
{
for(k=1;k<=14;k++)
{
printf(" ");
}
for(j=0;j<4;j++)
{
printf("*");
}
printf("\n");
}
for(i=1;i<4;i++)
{
for(j=0;j<c;j++)
{
printf("*");
}
printf("\n");
}
}
Exercise
6.16(a):
#include<stdio.h>
void main()
{
int j,i,n=5;
for(j=1;j<=n;j++)
{
for(i=1;i<=n;i++)
{
printf("s ");
}
printf("\n");
}
}
Exercise
6.16(b):
#include<stdio.h>
void main()
{
int j,i,n=5;
for(j=1;j<=n;j++)
{
if(j>1&&j<5)
{
printf("s s");
}
else
{
for(i=1;i<=n;i++)
{
printf("s ");
}
}
printf("\n");
}
}
Exercise
6.19:
#include<stdio.h>
void main()
{
int j,i,n=5;
for(j=1;j<=n;j++)
{
for(i=1;i<=n;i++)
{
if(i==3&&j==3)
{
printf("o ");
}
else
{
printf("s ");
}
}
printf("\n");
}
}
Vai review qsn gular ans den
ReplyDelete