#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter first number:");
scanf("%d",&a);
printf("Enter second number:");
scanf("%d",&b);
c=a*b;
printf("The Product is: %d", c);
getch();
}
2) Write a program to calculate area of triangle.
#include<stdio.h>
#include<conio.h>
void main()
{
int b,h;
float a;
printf("Enter breadth of triangle:");
scanf("%d",&b);
printf("Enter height of triangle: ");
scanf("%d",&h);
a= 0.5*b*h;
printf("Area is %f",a);
getch();
}
3) Write a program to enter two number and perform all arithmetic numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,a,d,p,di,mo;
printf("Enter first number:");
scanf("%d",&x);
printf("Enter second number:");
scanf("%d",&y);
a=x+y;
d=x-y;
p=x*y;
di=x/y;
mo=x%y;
printf("The sum is: %d \n", a);
printf("The difference is: %d \n", d);
printf("The product is: %d\n", p);
printf("The Division is: %d\n", di);
printf("The Remainder is: %d\n", mo);
getch();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int p,t,r;
int c;
printf("Enter principal, time and rate");
scanf("%d%d%d",&p,&t,&r);
c=p*(pow((1+r*0.01),t)) -p;
printf("Compound Interest is %d",c);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int l,a,p;
printf("Enter length of a square:");
scanf("%d",&l);
a=l*l;
p=4*l;
printf("Area of square is %d \n",a);
printf("Perimeter of square is %d",p);
getch();
}
##########
#
#
## #######
#
#
#include<stdio.h>
#include<conio.h>
void main()
{
printf("##########\n");
printf("#\n");
printf("# \n");
printf("##########\n");
printf("# \n");
printf("# ");
getch();
}
Question Related To Library Function
Write a program to show the use of.
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char lower='a';
char upper='B';
char digit='5';
char alnum='*';
printf("lower to upper: %c \n",toupper(lower));
printf("Upper to lower: %c \n",tolower(upper));
//use of isupper() and islower()
if(islower(lower))
{
printf("Character is lower\n");
}
if(isupper(upper))
{
printf("Character is Upper\n");
}
if(isalnum(alnum))
{
printf("This is alphanumeric");
}
else{
printf("This is not alphanumeric");
}
getch();
}
floor(), ceil(), squr(),log(),pow(base,pow)
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
double num=3.5,base=2,power=3;
printf("The Ceil of %f is %f \n",num,ceil(num));
printf("The floor of %f is %f \n",num,floor(num));
printf("The Square Root of %f is %f \n",num,sqrt(num));
printf("The Logarithm of %f is %f \n",num,log(num));
printf(" %f raised to power %f is %f \n",base,power,pow(base,power));
getch();
}
Ternary Operators
Solve the following by using ternary operator.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("Enter a no:");
scanf("%d",&a);
(a%2==0)?printf("The Number is even"):printf("The number is odd");
getch();
}
WAP to check whether the number is positive or negative;
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("Enter a no:");
scanf("%d",&a);
(a>0)?printf("The Number is Positive"):printf("The number is Negative");
getch();
}
Sequential Control Structure
#include<stdio.h>
#include<conio.h>
void main()
{
int a,c;
printf("Enter a no:");
scanf("%d",&a);
c=a*a*a;
printf("The cube of the number is:%d",c);
getch();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a;
printf("Enter a number:");
scanf("%d",&a);
//Without using library function
printf("Square without using library function: %d\n",a*a);
//using library function
int ans=pow(a,2);
printf("Square using library function: %d",ans);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int l,b,h,v,t;
printf("Enter Length of a cuboid:");
scanf("%d",&l);
printf("Enter Breadth of the cuboid:");
scanf("%d",&b);
printf("Enter Height of the cuboid:");
scanf("%d",&h);
t=2*(l*b+b*h+h*l);
v=l*b*h;
printf("The TSA of cuboid is %d \n The Volume of Cuboid is %d",t,v);
getch();
}
WAP to enter radious of circle and calculate area and circumference.
#include<stdio.h>
#include<conio.h>
void main()
{
float r,a,c;
const int pi=22/7;
printf("Enter radius of circle:");
scanf("%f",&r);
a=pi*r*r;
c=2*pi*r;
printf("The area of circle is: %f \n The circumference of circle is: %f",a,c);
getch();
}
Question Related To Decision Control Structure
#include<stdio.h>
#include<conio.h>
void main()
{
float m;
printf("Enter your mark:");
scanf("%f",&m);
if(m>=40)
{
printf("Pass");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("Enter a number");
scanf("%d",&n);
if(n%2==0)
{
printf("Even");
}
if(n%2!=0)
{
printf("Odd");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
printf("Enter a number");
scanf("%d",&age);
if(age>=18)
{
printf("He can vote");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int mark;
printf("Enter your mark:");
scanf("%d",&mark);
if(mark>=40)
{
printf("Pass");
}
else
{
printf("Fail");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("Enter a number:");
scanf("%d",&n);
if(n>0)
{
printf("Positive");
}
else
{
printf("Negative");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
printf("Enter a number");
scanf("%d",&age);
if(age>=18)
{
printf("He can vote");
}
else
{
printf("He can not vote");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("Enter a number:");
scanf("%d",&n);
if(n%2==0)
{
printf("Even");
}
else
{
printf("Odd");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("Enter a number:");
scanf("%d",&a);
printf("Enter Another number:");
scanf("%d",&b);
if(a>b)
{
printf("%d is greater",a);
}
else
{
printf("%d is greater",b);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter first number:");
scanf("%d",&a);
printf("Enter second number:");
scanf("%d",&b);
printf("Enter third number:");
scanf("%d",&c);
if(a>b)
{
if(a>c)
{
printf("a is greatest");
}
else
{
printf("c is greatest");
}
}
else{
if(b>c)
{
printf("b is greatest");
}
else
{
printf("c is greatest");
}
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("Enter first number:");
scanf("%d",&a);
if(a>0)
{
printf("Positive");
}
else if(a<0)
{
printf("Negative");
}
else
{
printf("Zero");
}
getch();
}
iii. percentage>=45 and <60 second division
#include<stdio.h>
#include<conio.h>
void main()
{
int m1,m2,m3,m4,m5,percentage;
printf("Enter mark of subject 1: ");
scanf("%d",&m1);
printf("Enter mark of subject 2: ");
scanf("%d",&m2);
printf("Enter mark of subject 3: ");
scanf("%d",&m3);
printf("Enter mark of subject 4: ");
scanf("%d",&m4);
printf("Enter mark of subject 5: ");
scanf("%d",&m5);
percentage=(m1+m2+m3+m4+m5)/5;
printf("Percentage: %d",percentage);
if(percentage>=75 && percentage<=100)
{
printf("Distinction");
}
else if(percentage>=60 && percentage<75)
{
printf("First");
}
else if(percentage>=45 && percentage<60)
{
printf("Second");
}
else if(percentage>=35 && percentage<45)
{
printf("\n Pass");
}
else
{
printf("\n Fail");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter first number:");
scanf("%d",&a);
printf("Enter second number:");
scanf("%d",&b);
printf("Enter third number:");
scanf("%d",&c);
if(a>b && a>c)
{
printf("a is greatest");
}
else if(b>c)
{
printf("b is greatest");
}
else
{
printf("c is greatest");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter first number:");
scanf("%d",&a);
printf("Enter second number:");
scanf("%d",&b);
printf("Enter third number:");
scanf("%d",&c);
if((b>a && b<c) || (b>c && b<a))
{
printf("b is middle number ");
}
else if((a>b && a<c) || (a>c && a<b))
{
printf("a is middle number");
}
else
{
printf("c is middle number");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int choice;
printf("1. sunday \n 2. Monday \n 3. Tuesday \n 4. Wednesday \n 5. Thursday \n 6. Friday \n 7. Saturday");
printf("\n choose anyone, enter number (1,2....7):");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Sunday");
break;
case 2:
printf("Monday");
break;
case 3:
printf("Tuesday");
break;
case 4:
printf("Wednesday");
break;
case 5:
printf("Thursday");
break;
case 6:
printf("Sunday");
break;
case 7:
printf("Friday");
break;
default:
printf("Not valid Input");
break;
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int l,b,r;
char choice;
printf("a. Area of Rectangle \n b. Perimeter of Rectangle \n c. Area of circle \n d. Area of square ");
printf("\n choose anyone, (a,b,c,d):");
scanf("%c",&choice);
switch(choice)
{
case 'a':
printf("Enter lenght of Rectangle: ");
scanf("%d",&l);
printf("Enter Breadth of Rectangle: ");
scanf("%d",&b);
printf("Area of the Rectangle is %d",l*b);
break;
case 'b':
printf("Enter lenght of Rectangle: ");
scanf("%d",&l);
printf("Enter Breadth of Rectangle: ");
scanf("%d",&b);
printf("Perimeter of the Rectangle is %d",2*(l+b));
break;
case 'c':
printf("Enter radious of circle: ");
scanf("%d",&r);
printf("Perimeter of the circle is is %d",2*22/7*r);
break;
case 'd':
printf("Enter length of square: ");
scanf("%d",&l);
printf("area of the suare is is %d",l*l);
break;
default:
printf("Not valid Input");
break;
}
getch();
}
Menu
Addition of two numbers
Subtraction of two numbers
Multiplication of two numbers
Division of two numbers
Exit
Note: user’s choice should be ‘a’ for addition, ‘s’ for subtraction, ‘m’ for multiplication, ‘d’ for division and ‘e’ for exit.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
char choice;
printf(" Addition of two numbers \n Substraction of two numbers \n Multiplication of two numbers \n Division Of Two Numbers \n Exit");
printf("'a' for addition, 's' for subtraction, 'm' for multiplication, 'd' for division and 'e' for exit.");
scanf("%c",&choice);
switch(choice)
{
case 'a':
printf("Enter first Number: ");
scanf("%d",&a);
printf("Enter second Number: ");
scanf("%d",&b);
printf("Additon of two number is %d",a+b);
break;
case 's':
printf("Enter first Number: ");
scanf("%d",&a);
printf("Enter second Number: ");
scanf("%d",&b);
printf("Substraction of two number is %d",a-b);
break;
case 'm':
printf("Enter first Number: ");
scanf("%d",&a);
printf("Enter second Number: ");
scanf("%d",&b);
printf("Multiplication of two number is %d",a*b);
break;
case 'd':
printf("Enter first Number: ");
scanf("%d",&a);
printf("Enter second Number: ");
scanf("%d",&b);
printf("Divison of two number is %d",a/b);
break;
case 'e':
break;
default:
printf("Invalid Input ");
break;
}
getch();
} Question related To Unconditional Statement.
1. WAP to allow user to enter only value under 100 by using Goto statement.
#include<conio.h>
#include<stdio.h>
void main()
{
int n;
label:
printf("Enter a number ");
scanf("%d",&n);
if(n>99)
{
goto label;
}
else
{
printf("You have entered value under 100");
}
getch();
}
STRUCTURE (Submit after Mid Term , 15 Ashad 2083) A) MCQ 1. What is the…
FUNCTION (Assignment) Submit Before Mid Term MCQ 1. What is the output of this statement…
Evolution History of computer Technology (HISTORY OF COMPUTER) Evolution of computer is a study of…
Unit3_ClassMethodDesign_OOAD DOWNLOAD
Maturity of Enterprise Architecture Practice Maturity of Enterprise Architecture Practice DOWNLOAD
Report-on-final-project_Sample_2