EXERCISE CHAPTER NO. 4 " CHOICES and DECISIONS"
Chapter No. 4:
Question No. 3
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
char
c;
int
n,uc=0,sc=0;
printf("Enter
a phrase = ");
c=getche();
while(c!='\r')
{
if(n>=65
&& n<=90)
uc++;
if(n>=97
&& n<=122)
sc++;
c=getche();
}
clrscr();
printf("Number
of Upper case characters = %d\n",uc);
printf("Number
of Small case characters = %d",sc);
getch();
}
Chapter No. 4:
Question No. 4
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int
a,b,c;
printf("Enter
3 integer values seprated with space = ");
scanf("%d
%d %d",&a,&b,&c);
if(a>b
&& a>c)
printf("A
is the largest number");
else
if(b>a && b>c)
printf("B
is the largest number");
else
if(c>a && c>b)
printf("C
is the largest number");
else
printf("All
numbers are equal");
getch();
}
Chapter No. 4:
Question No. 5
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int
total=0,fail=0,max=0,n;
float
avg;
for(int
i=1;i<=35;i++)
{
printf("Enter
marks between 0 to 100 = ");
scanf("%d",&n);
total+=n;
if(n<50)
fail++;
if(n==100)
max++;
}
avg=total/35;
printf("Average
= %f\n",avg);
printf("No
of Failed Students = %d\n",fail);
printf("No
of students secured 100 marks = %d",max);
getch();
}
Chapter No. 4:
Question No. 6
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
for(int
i=1;i<=100;i++)
{
if(i%2!=0
&& i%7!=0)
printf("%d\n",i);
}
getch();
}
Chapter No. 4:
Question No. 7
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int
a,b,n,gcd;
printf("Enter
first integer value = ");
scanf("%d",&a);
printf("Enter
second integer value = ");
scanf("%d",&b);
if(a<b)
{
n=a;
}
else
{
n=b;
}
for(int
i=1;i<=n;i++)
{
if(a%i==0
&& b%i==0)
{
gcd=i;
}
}
printf("GCD
= %d",gcd);
getch();
}
Chapter No. 4:
Question No. 8
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
clrscr();
int
a,b,c;
float
r1,r2,n;
printf("Enter
integer value of a = ");
scanf("%d",&a);
printf("Enter
integer value of b = ");
scanf("%d",&b);
printf("Enter
integer value of c = ");
scanf("%d",&c);
n=pow(b,2)-4*a*c;
if(n<=0)
{
printf("No
Real Solution");
}
else
{
r1=(-b+sqrt(n))/(2*a);
printf("First
result = %f\n",r1);
r2=(-b-sqrt(n))/(2*a);
printf("Second
result = %f\n",r2);
}
getch();
}
No comments:
Post a Comment