Académique Documents
Professionnel Documents
Culture Documents
th
Exercise
Chaptor-1 Getting Started
(Valid)
(valid)
(valid)
(Valid)
5th:2+1+2+3;
6th:8;
(c)s=qui*add/4-6/2+2/3*6/god;(qui=4,add=2,god=2,assume s to be an int)?
1st:4*2/4-6/2+2/3*6/2;
2nd:8/4-6/2+2/3*6/2;
3rd:2-6/2+2/3*6/2;
4th:2-3+2/3*6/2;
5th:2-3+0*6/2;(zero)
6th:-1;
(d)s=1/3*a/4-6/2+2/3*6/g;(a=4,g=3,assume s to be int)?
1st:1/3*4/4-6/2+2/3*6/3;
2nd:0*4/4-6/2+2/3*6/3;
3rd:0/4-6/2+2/3*6/3;
4th:0-6/2+2/3*6/3;
5th:-3+2/3*6/3;
6th:-3+0*6/3;
7th:-3;
[D]fill the following table for the expression given below and than evaluate the
result. A sample entry has been filled in the table for expression (a).
(a) g=10/5/2/1;
Operator
/
Left
10
Right
5 or 5/2/1
2 or 2/1
1 or 1/1
Remark
Left operand is
unambiguous right is
not
Left operand is
unambiguous right is
not
Left operand is
unambiguous right is
not
(b)b=3/2+5*4/3;
Operator
/
Left
3
Right
2 or 2+5*4/3
4 or 4/3
20
1.5
6.67
Left
3
Right
4
Remark
Left operand is
unambiguous right is
not
Left operand is
unambiguous right is
not
both operand is
unambiguous
both operand is
unambiguous
(c)a=b=c=3+4;
Operator
+
Remark
both operand is
unambiguous
(a+b)*(1/m)
Z=(8.8*(a+b)*2/c-0.5+2*a/(q+r))
/ ((a+b)*(1/m));
(b)x=-b+(b*b)+2 4ac / 2a
X=(-b+b*b+2*(4*a*c)) / ( 2*a);
(c)R=2v+6.22(c+d) / g+v
R=2*v+6.22*(c+d)/(g+v) ;
(d)A=7.7b(xy+a)/c-0.8+2b / (x+a)(1/y)
A=(7.7*b*(x*y+a)/c-0.8+2*b)/((x+a)*(1/y));
float a,b;
k=i/j*j;
l=j/i*I;
a=i/j*j;
b=j/i*I;
printf(%d%d%f%f,k,l,a,b);
}
ans: output=021.993
(b)main(){
Int a,b;
a=-33;
b=-3(-3);
printf(a=%d b=%d,a,b);
}
Output=Throw Error value required.
(c)main(){
float a=5,b=2;
int c;
c=a%b;
printf(%d,c);
}
Output=1
(d)main(){
Printf(nn \n\n nn\n);
Printf(nn /n/n nn/n);
}
Output =nn
nn
nn/n/n n/n
(e)main(){
Int a,b;
printf(enter the value of a and b);
scanf(%d%d,&a,&b);
printf(a=%d b=%d,a,b);
}
Output = this will print the value entered by the user.
(f)main(){
Int p,q;
Printf(enter the value of p and q);
Scanf(%d%d,p,q);
Printf(p=%d q=%d,p,q);
}
Output =hear we will get garbage value or any random value.
(z) What will be the value of d if d is float after the operation d=2/7.0.-(2)0.2857
#include<stdio.h>
#include<conio.h>
main(){
int salary,dAllowance,hAllowance,gSalary;
printf("Enter the amount of salary");
scanf("%d",&salary);
dAllowance=salary*0.4;
printf("your dearness allowance is %d \n",dAllowance);
hAllowance=salary*0.2;
printf("your house rent allowance is %d\n",hAllowance);
gSalary=salary+dAllowance+hAllowance;
printf("your gross salary is %d",gSalary);
getch();
}
(b)The distance between two cities (in km.)Is input throw the keyboard. Write a program to
convert and print this distance in mtr, inches and centimeters?
Ans:
#include<stdio.h>
#include<conio.h>
main(){
int distance,meters,inches,centimeters;
printf("Enter the distance in km. :");
scanf("%d",&distance);
meters=distance*1000;
printf("your distance in meters is : %d \n",meters);
inches=meters*3;
(c)If the marks obtained by the student in five different subjects are input through the
keyboard,find out the aggregate marks and percentage marks obtained by the student. Assume that
the maximum marks that can be obtained by the student in each subject is 100.
Ans:
#include<stdio.h>
#include<conio.h>
main(){
int agMarks,sub1,sub2,sub3,sub4,sub5;
float pMarks;
printf("Enter the marks of subject :");
scanf("%d%d%d%d%d",&sub1,&sub2,&sub3,&sub4,&sub5);
agMarks=(sub1+sub2+sub3+sub4+sub5)/5;
printf("your aggregate marks
is : %d \n",agMarks);
pMarks=(sub1+sub2+sub3+sub4+sub5)/500.0*100;
printf("your pecentage marks is %f",pMarks);
getch();
}
#include<stdio.h>
#include<conio.h>
main(){
int dgfahren;
float dgcent;
printf("Enter degrees in fahrenheit :");
scanf("%d",&dgfahren);
dgcent=5.0/9*(dgfahren-32);
printf("Degree in centigrade is : %f",dgcent);
getch();
}
(e)The length and breadth of a rectangle and radius of a circle are input through the keyboard
write a program to calculate area and perimeter of the rectangle,and the area and the circumference
of the circle.
Ans:
#include<stdio.h>
#include<conio.h>
main(){
int length,breadth,rArea,rPerimeter;
float radius,cArea,cCircum;
printf("Enter the Length and Breadth of ractangle :");
scanf("%d%d",&length,&breadth);
rArea=length*breadth;
printf("Area of a Ractangle is :%d\n",rArea);
rPerimeter=2*(length+breadth);
printf("Perimeter of a Ractangle is :%d\n\n\n",rPerimeter);
printf("Enter the Radius of a Circle :");
scanf("%f",&radius);
cArea=3.14*(radius*radius);
printf("Area of a circle is :%f\n",cArea);
cCircum=2*3.14*radius;
printf("Circumference of a circle is:%f",cCircum);
getch();
}
(f)Two numbers are input through the keyboard in two location C and D.write a program to
interchange the contents of C and D.
Ans:
#include<stdio.h>
#include<conio.h>
main(){
int c,d,e;
float radius,cArea,cCircum;
printf("Enter the value of C and D :");
scanf("%d%d",&c,&d);
e=c;
c=d;
d=e;
printf("Value after interchange is :%d%d\n",c,d);
getch();
}
(g)If a five digit Number is input through the keyboard,write a program to calculate the sum of
its digit.
Ans:
#include<stdio.h>
#include<conio.h>
main(){
long
int number,one,two,three,four,five,total;
clrscr();
printf("Enter a five degit number");
scanf("%ld",&number);
one=number%10;
number=number/10;
two=number%10;
number=number/10;
three=number%10;
number=number/10;
four=number%10;
number=number/10;
five=number%10;
total=one+two+three+four+five;
(h)If a five digit number is input through the keyboard,write a program to reverse the number.
Ans:
#include<stdio.h>
#include<conio.h>
main(){
long int number,one,two,three,four,five,rNumber=0;
clrscr();
printf("Enter a five degit number");
scanf("%ld",&number);
one=number%10;
number=number/10;
rNumber=rNumber*10+one;
two=number%10;
rNumber=rNumber*10+two;
number=number/10;
three=number%10;
rNumber=rNumber*10+three;
number=number/10;
four=number%10;
rNumber=rNumber*10+four;
number=number/10;
rNumber=rNumber*10+number;
printf("Reverse number is :%ld",rNumber);
getch();
}
(i)If a four digit number is input through the keyboard,write a program to obtain the sum of
the first and last digit of this number.
Ans:
#include<stdio.h>
#include<conio.h>
main(){
int number,first,last;
printf("Enter any Four digit number");
scanf("%d",&number);
first=number%10;
number=number/10;
number=number/10;
number=number/10;
last=number;
number=first+last;
printf("This is your answer :%d",number);
getch();
}
(j)In a town,the percentage of man is 52.the percentage of total literacy is 48.if total
percentage of literate man is 35 of the population,write a program to find a total number of illiterate
man and women if the population of town is 80,000.
Ans:
#include<stdio.h>
#include<conio.h>
main(){
long int
population,man,women,litMan,illitMan,litWomen,illitWomen,literacy;
clrscr();
printf("Enter the Total population :");
scanf("%ld",&population);
printf("Enter percentage of Man :");
scanf("%ld",&man);
printf("Enter the percentage of literacy :");
scanf("%ld",&literacy);
(k)A cashier has a currency notes of denomination 10, 50,100.if the amount to be withdrawn
is input throw the keyboard in hundreds, find the total number of currency notes of each
domination the cashier will have to give to the withdrawer.
Ans:Remaining
(l)If the total selling price of 15 items and the total profit earned on them is input through
keyboard, write a program to find cost price of one item.
Ans:
#include<stdio.h>
#include<conio.h>
main(){
long int tsPrice,profit,cPrice,sPrice,pProfit;
clrscr();
printf("Enter total selling price :");
scanf("%ld",&tsPrice);
printf("Enter profit price :");
scanf("%ld",&profit);
sPrice=tsPrice/15;
pProfit=profit/15;
cPrice=sPrice-pProfit;
printf("Cost price per Unit :%ld",cPrice);
getch();
}
(m)If a five digit number is input through keyboard,write a program to print a new number by
adding one to each of its digit for example if the number that is input 12391 than output should be
displayed as 23402
Ans:
#include<stdio.h>
#include<conio.h>
main(){
long int number,one,two,three,four,five;
clrscr();
printf("Enter the five digit number :");
scanf("%ld",&number);
one=number%10+1;
number=number/10;
two=number%10+1;
number=number/10;
three=number%10+1;
number=number/10;
four=number%10+1;
number=number/10;
five=number%10+1;
printf("now your new value is
:%ld%ld%ld%ld%ld",five,four,three,two,one);
getch();