#include<stdio.h> int main() { int n; scanf("%d",&n); if(n<=10) { printf("%d",n*n); } else if(n>10&&n<=20) { printf("%d",n*n*n); } else if(n>20) { printf("Invalid Number"); } return 0; }
Archive for the ‘Lab 10B’ Category
6.Consider a number is input through keyboard. If number is between 0 to 10 then square the number. If number is between 11 to 20 then cube the number and for all other conditions number will be as it is. WAP for the same.
Posted: September 17, 2012 in CSE Sem1, ECE Sem1, Lab 10, Lab 10, Lab 10B, Lab 10B, MECH Sem10
5.Consider a number is input through keyboard. WAP to find that the number is greater than 1000, if yes then print the double of the number and if no then print 0
Posted: September 17, 2012 in CSE Sem1, ECE Sem1, Lab 10, Lab 10, Lab 10B, Lab 10B, MECH Sem1#include<stdio.h> int main() { int n; scanf("%d",&n); if(n>1000) { printf("%d",2*n); } else printf("0"); return 0; }
4.Write a program to check whether a triangle is valid or not, when the three angles of triangle are entered through the keyboard. A triangle is valid if the sum of all three angles is equal to 180 degrees.
Posted: September 17, 2012 in CSE Sem1, ECE Sem1, Lab 10B, Lab 10B#include<stdio.h> void main() { float a,b,c,sum; printf("enter three angles a,b,c"); scanf("%f%f%f",&a,&b,&c); sum=a+b+c; if(sum==180) printf("triangle is valid"); else printf("triangle is not valid"); }
3.If cost and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred.
Posted: September 17, 2012 in CSE Sem1, ECE Sem1, Lab 10, Lab 10, Lab 10B, Lab 10B, MECH Sem1#include<stdio.h> void main() { int cp,sp,pro,loss; printf("Enter sp and cp"); scanf("%d%d",&cp,&sp); if(cp>sp) { loss=cp-sp; printf("loss is %d",loss); } else { pro=sp-cp; printf("pro is %d",pro); } }
Practical B)Exercise2: If the ages of Ram, Shayam and Ajay are input through the keyboard, write a program to determine the youngest of three.
Posted: September 17, 2012 in CSE Sem1, ECE Sem1, Lab 10B, Lab 10B#include<stdio.h> #include<math.h> void main() { int ajay,ram,shyam; printf("enter the ages of ajay,ram,shyam"); scanf("%d%d%d",&ajay,&ram,­am); if((ajay>ram)&&(shyam>ajay)) { printf("\n the youngest of the three is ram"); } if((ram>ajay)&&(shyam>ajay)) { printf("\n the youngest of the three is ajay"); } if((ram>shyam)&&(ajay>shyam)) { printf("\n the youngest of the three is shyam"); } }
Practical B Exercise1: A five digit number is entered through the keyboard. Write a program to obtain the reversed number and to determine whether the original and reversed numbers are equal or not.
Posted: September 17, 2012 in CSE Sem1, ECE Sem1, Lab 10B, Lab 10B#include<stdio.h> #include<math.h> void main() { int num,num1,rev=0,p=4,temp; printf("Enter num"); scanf("%d",&num); temp=num; while(num>0) { num1=num%10; rev=rev+num1*pow(10,p--); num=num/10; } printf("%d",rev); if(rev==temp) { printf("Reversed no.is equal"); } else { printf("Reversed no. is not equal"); } }
3)Ram’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary
Posted: September 17, 2012 in CSE Sem1, ECE Sem1, Lab 10B, Lab 10B#include<stdio.h> void main() { float bs,da,hr,gs; printf("Enter bs"); scanf("%f",&bs); da=(40*bs)/100; hr=(20*bs)/100; gs=bs+da+hr; printf("%f\n%f\n%f\n",da,hr,gs); }
A c program contains the following declarations and initial assignments: int i=8,j=5,k; float x=0.005,y=-0.01,z; char a,b,c=’c’,d=’d’; Determine the value of each of the following assignment expression expressions. Use the values initially assigned to the variables for each expression. (e) i=i%j
Posted: September 17, 2012 in CSE Sem1, ECE Sem1, Lab 10B, Lab 10B#include<stdio.h> int main() { int i=8,j=5; i=(i%j); printf("%d",i); return 0; }