Q1.Write a program to calculate and print the area of a square.....
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int height,width,area;
height=5;
width=4;
area=height*width;
printf("Area of square=%d",area);
getch();
}
Q2.Write a program that adds two floating point numbers and shows their sum on the screen............#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int height,width,area;
height=5;
width=4;
area=height*width;
printf("Area of square=%d",area);
getch();
}
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
float var1,var2,res;
var1=24.27;
var2=41.50;
res=var1+var2;
printf("%f + %f=%f",var1,var2,res);
getch();
}
Q3.Write a program to convert the distance in kilometers into meters.........
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
double meter,kilometer;
printf("Enter distance in kilometers:");
scanf("%lf",&kilometer);
meter=kilometer*1000;
printf("\n%lf kilometers=%lf meters",kilometer,meter);
getch();
}
Q4.Write a program that displays the ASCII code of the character typed by the user.....
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char ch;
printf("Enter a character:");
ch=getche();
printf("\nThe ASCII code for \'%c\' is %d",ch,ch);
}
Q5.Write a program that displays the value stored in a string variable name......
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char name[ ]="ZAIN";
printf("Name is %s",name);
getch();
}
Q6.Write a program to display the following output using single printf statement.......
*
* *
* * *
* * * *
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("*\n**\n***\n****");
getch();
}
Q7.Write a program that inputs base and height from the user and calculates area of a triangle by using the formula Area=1/2*Base*Height........
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float base,height;
double area;
printf("Enter base:");
scanf("%f",&base);
printf("Enter height:");
scanf("%f",&height);
area=0.5*base*height;
printf("Area=%5.2f",area);
getch();
}
Q8.Write a program that inputs name,age and address from the user and displays it on the screen......
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char name[25],address[30];
int age;
printf("Enter your age:");
scanf("%d",&age);
printf("Enter your name:");
scanf("%s",name);
printf("Enter your address:");
scanf("%s",address);
printf("your name is %s\n",name);
printf("your address is %s\n",address);
printf("your age is %d\n",age);
getch();
}
Q9.Write a program that gets temperature from the user in celsius and converts it into Fahrenheit using the formula F=9/5*C+32.......
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float cel,faren;
printf("Enter temperature in celcius:");
scanf("%f",&cel);
faren=9.0/5.0*cel+32;
printf("Temperature in Fahrenheit is %5.2f",faren);
getch();
}
Q10.Write a program that gets a three-digit number from the user and displays it in reverse order.For example if the user enter 123,it displays 321.....
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,a,b;
printf("Enter 3-digit number:");
scanf("%d",&n);
a=n/100;
n=n%100;
b=n/10;
n=n%10;
printf("Number in reverse order is %d%d%d",n,b,a);
getch();
}
Q11.Write a program that inputs 4 numbers and calculates the sum,average, and product of all the numbers....
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,sum,product;
float avg;
printf("Enter 4 numbers:");
scanf("%d%d%d%d",&a,&b,&c,&d);
sum=a+b+c+d;
product=a*b*c*d;
avg=sum/4.0;
printf("Sum of all numbers:%d\n",sum);
printf("Product of all numbers:%d\n",product);
printf("Average of all numbers:%5.2f",avg);
getch();
}
Q12.Write a program that converts a person's height from inches to centimeters using the formula 2.54*height.....
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int height;
float height_in_cent;
printf("Enter height in inches:");
scanf("%d",&height);
height_in_cent=height*2.54;
printf("Your height in centimeters is:%f",height_in_cent);
getch();
}
Q13.Write a program that inputs two numbers and exchanges their values.The program should display the values of variables before and after exchange.....
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x,y,temp;
printf("Enter two numbers:");
scanf("%d%d",&x,&y);
printf("Value in x:%d\n",x);
printf("Value in y:%d\n",y);
temp=x;
x=y;
y=temp;
printf("Value in x after exchange:%d\n",x);
printf("Value in y after exchange:%d\n",y);
getch();
}
Q14.Write a program to find out the area of triangle when three sides a, b and c of the triangle are given.Use appropriate statements to input the values of a, b and c from the keyboard.Formula for the area or triangle is Area=(s(s-a)(s-b)(s-c))1/2 where s=(a+b+c)/2...
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float a,b,c;
double s,area;
printf("Enter side A:");
scanf("%f",&a);
printf("Enter side B:");
scanf("%f",&b);
printf("Enter side C:");
scanf("%f",&c);
s=(a+b+c)/2.0;
area=sqrt(s*(s-a)*(s-b)+(s-c));
printf("Area of triangle is %f",area);
getch();
}
Q15.Write a program that inputs radius of sphere from the user.Calculates its volume and surface area using the formula Area=4*3.14*r*r and circumference=4/3*3.14*r*r*r....
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float r,area,cir;
printf("Enter radius:");
scanf("%f",&r);
area=4.0*3.14*r*r;
cir=(4.0/3.0)*3.14*r*r*r;
printf("\nArea is %5.25f\n",area);
printf("Circumference is %5.2f\n",cir);
getch();
}
Q16.Write a program that converts a temperature in degrees.Farhenheit to degrees Celsicus.For conversion,use the following formula C=5/9(F-32)....
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float cel,faren;
printf("Enter temperature in farenheit:");
scanf("%d",&faren);
cel=5.0/9.0*(faren-32);
printf("Temperature in celcius is %f",cel);
getch();
}
Q17.Write a program that displays the following shape using nested loops.The outer loop should be for loop and inner loop should be while loop..
*******
******
*****
****
***
**
*
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=7;i++)
{
j=i;
while(j<=7)
{
printf("*");
j++;
}
printf("\n");
}
getch();
}