Q1(a).. Write a C program to accept dimensions of a cylinder and display the surface area and volume of cylinder.
#include<stdio.h>
int main()
{
float r,h,v,A; //declare variables r=radius, h=height , v=volume , A=area float p=3.14;
//accepting radius(r) and height(h) printf("\nEnter Value of radius:"); scanf("%f",&r);
printf("\nEnter Value of height:"); scanf("%f",&h);
A=(2*p*r*h)+(2*p*r*r); //formula of surface area of cylinder v=p*r*r*h; //formula of volume of cylinder
printf("Surface Area of Cylinder :- %f ",A); printf("Volume of Cylinder :- %f ",v);
}
Q2(a).. Write a C program to accept radius of a circle and display the area and circumference of a circle.
#include<stdio.h>
int main()
{
int radius;
float PI=3.14,area,ci;
printf(" Enter the Radius of Circle: ");
scanf("%d",&radius);
area = PI * radius * radius;
printf("\n Area of a Circle : %f ",area);
ci = 2 * PI * radius;
printf("\n Circumference of a Circle is : %f ",ci);
return(0);
}
Q3(a) Write a C program to accept temperatures in Fahrenheit (F) and display it in Celsius(C) and Kelvin (K) (Hint: C=5.0/9(F-32), K = C + 273.15)
#include<stdio.h>
#include<conio.h>
int main()
{
float fahrenheit,convert;
//Accept temperature
printf("\nEnter temperature in fahrenheit:");
scanf("%f",&fahrenheit);
convert=(fahrenheit - 32) * 5/9; // Formula C=5.0/9(F-32)
//To display temperature
printf("\nTemperature in celsius: %f",convert);
}
Q4(a).. Write a C program to accept two numbers and print arithmetic and harmonic mean of the two numbers (Hint: AM= (a+b)/2 ,HM = ab/(a+b) )
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
float AM, HM; // AM=Arithmetic Mean , HM=Harmonic Mean
//Accept 2 numbers
printf("Enter the 1st number: ");
scanf("%d",&a);
printf("Enter the 2nd number: "); scanf("%d",&b);
AM=float((a+b))/2; // Formula
AM= (a+b)/2 HM=a*b/float((a+b)); // Formula HM = ab/(a+b)
//To display Arithmetic Mean & Harmonic Mean printf("Arithmetic Mean is: %f",AM);
printf("\nHarmonic Mean is: %f",HM);
getch();
}
Q5(a)Write a C program to accept dimensions length (l), breadth(b) and height(h) of a cuboids and display surface area and volume (Hint : surface area=2(lb+lh+bh ), volume=lbh )
#include<conio.h>
#include<stdio.h>
int main()
{
float l,b,h,area,volume; // l=length , b=breadth , h=height
printf("\nEnter value of lenght:");
scanf("%f",&l);
printf("\nEnter value of breadth:"); scanf("%f",&b);
printf("\nEnter value of height:"); scanf("%f",&h);
//formula of surface area of a cuboids area=2*(l*b+l*h+b*h);
//formula of volume of a cuboids volume=l*b*h;
printf("\nSurface area of cuboids: %f",area); printf("\nVolume of cuboids: %f",volume);
getch();
}
Q6(a) Write a C Program to accept a character from the keyboard and display its previous and next character in order. Ex. If character entered is ‘d’, display “The previous character
is c”, “The next character is e”.
#include<stdio.h>
#include<conio.h>
int main()
{
char letter;
//accept character
printf("Enter the character: ");
scanf("%c",&letter);
printf("Previous character of %c is %c", letter, letter-1); printf("\nNext character of %c is %c",letter, letter+1);
getch();
}
Q7(a)Write a C program to accept the x and y coordinates of two points and compute the distance between the two points.
#include<conio.h>
#include<stdio.h>
//To calculate distance between 2 points
void distance(float x1,float y1,float x2,float y2)
{
float ans1,ans2; ans1=x1-x2;
ans2=y1-y2;
// %f is place holder for floating point values
printf("Distance between two points is: %f x %f y.",ans1,ans2);
}
int main()
{
float x1,y1,x2,y2; //declaration of x1,y1,x2,y2
//accept values of x1,x2,y1,y2 printf("\nEnter value of x1: "); scanf("%f",&x1);
printf("\nEnter value of y1: "); scanf("%f",&y1);
printf("\nEnter value of x2: "); scanf("%f",&x2);
printf("\nEnter value of y2: "); scanf("%f",&y2);
//calling distance function distance(x1,y1,x2,y2);
getch();
}
Q8(a) A cashier has currency notes of denomination 1, 5 and 10. Write a C program to accept the withdrawal amount from the user and display the total number of currency notes of
each denomination the cashier will have to give.
#include<stdio.h>
int main()
{
int w,x,y,z;
printf("enter withdrow amount : ");
scanf("%d",&w)
x=w/10;
w=w%10;
y=w/5;
w=w%5;
z=w;
printf("note of 10 : %d\n",x);
printf("note of 5 : %d\n",y);
printf("note of 1 : %d\n",z);
Q9(a).. Write a C program to accept a character from the user and check whether the character is a vowel or consonant.
#include<stdio.h>
int main()
{
char c;
int lowercase_vowel, uppercase_vowel; printf("Enter an alphabet: ");
scanf("%c", &c);
lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' ||c == 'u'); uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' ||c == 'U');
if (lowercase_vowel || uppercase_vowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
return 0;
}
Q10(a)Write a C program to accept the x and y coordinate of a point and find the quadrant in which the point lies.
#include <stdio.h>
int main()
{
int co1,co2;
printf("Input the values for X and Y coordinate : "); scanf("%d %d",&co1,&co2);
if( co1 > 0 && co2 > 0)
printf("The coordinate point (%d,%d) lies in the First quandrant.\n",co1,co2);
else if( co1 < 0 && co2 > 0)
printf("The coordinate point (%d,%d) lies in the Second quandrant.\n",co1,co2);
else if( co1 < 0 && co2 < 0)
printf("The coordinate point (%d, %d) lies in the Third quandrant.\n",co1,co2);
else if( co1 > 0 && co2 < 0)
printf("The coordinate point (%d,%d) lies in the Fourth quandrant.\n",co1,co2);
else if( co1 == 0 && co2 == 0)
printf("The coordinate point (%d,%d) lies at the origin.\n",co1,co2);
}
Q11(a)Write a C program to accept the cost price and selling price from the user. Find out if the seller has made a profit or loss and display how much profit or loss has been made.
#include<stdio.h> #include<conio.h>
int main()
{
int cp,sp; //cp=cost price, sp=selling price
float profit,loss;
//accept cost price and cost price printf("\nEnter cost price: "); scanf("%d",&cp);
printf("\nEnter selling price: "); scanf("%d",&sp);
//check selling price is greater than cost price or not if(sp<cp)
{
loss=(cp-sp);
printf("\nSeller has made loss"); printf("\nloss = %f Rs.",loss);
}
else if(sp>cp)
{
profit=(sp-cp);
printf("seller has made profit");
printf("\nprofit= %f Rs.",profit);
}
else
{
}
printf("seller has made nor profit nor loss");
getch();
}
Q12(a)Write a C program to calculate sum of digits of a given input number.
#include <stdio.h>
main()
{
int n, t, sum = 0, remainder; printf("Enter an integer\n"); scanf("%d", &n);
t = n;
while (t != 0)
{
remainder = t % 10;
sum = sum + remainder;
t = t / 10;
}
printf("Sum of digits of %d = %d\n", n, sum);
return 0;
}
Q13(a)Write a C program to accept the value of n and display sum of all odd numbers up to n.
#include <stdio.h> void main()
{
int i,n,sum=0,a;
printf("Input number of terms : ");
scanf("%d",&n);
printf("\nThe odd numbers are :");
for(i=1;i<=n;i++)
{
a=(2*i)-1; printf("%d ",a); sum=sum+a;
}
printf("\nThe Sum of odd Natural Number upto %d terms : %d\n",n,sum);
}
Q14(a).. Write a C program to check whether a input number is Armstrong number or not.
Ans:
#include <stdio.h>
int main()
{
printf("Input a number: "); scanf("%d",&num);
for(temp=num;num!=0;num=num/10)
{
r=num % 10;
sum=sum+(r*r*r);
}
printf("%d is not an Armstrong number.\n",temp);
Q15 (a). Write a C program to check whether a input number is perfect number of not.
For example 6 is perfect number since divisor of 6 are 1, 2 and 3. Sum of its divisor is 1 + 2+ 3
= 6*/
Ans:
#include <stdio.h>
int main()
{
int n,i,sum; int mn,mx;
printf("Input the number : "); scanf("%d",&n);
sum = 0;
printf("The positive divisor : ");
for (i=1;i<n;i++)
{
if(n%i==0)
{
sum=sum+i;
printf("%d",i);
}
}
printf("\nThe sum of the divisor is : %d",sum);
if(sum==n)
printf("\nSo, the number is perfect.");
else
printf("\nSo, the number is not perfect.");
printf("\n");
}
Q16(a). Write a C program to calculate xy without using standard library function.
Ans:
#include<stdio.h>
#include<conio.h>
int main()
{
int i,x,y, ans;
clrscr(); ans=1;
printf("Enter the value of x"); scanf("%d", &x); printf("Enter the value of y"); scanf("%d", &y);
for(i=1; i<=y; i++)
{
ans= ans*x;
}
printf(" %d to the power %d is %d", x, y, ans); getch();
}
Q17(a).. Write a C program to display multiplication table of a given input number .
#include <stdio.h>
int main()
{
int j,n;
printf("Input the number (Table to be calculated) : "); scanf("%d",&n);
printf("\n"); for(j=1;j<=10;j++)
{
printf("%d X %d = %d \n",n,j,n*j);
}
}
Q18(a). Write a C program to generate following triangle up to n lines.
1
1 2
1 2 3
#include<stdio.h> void main()
{
int i,j,n;
printf("Enter number: "); // To accept number from user scanf("%d",&n);
//outer for loop is used to print rows and the inner loop is used to print columns
for(i=1;i<=n;i++) //outer loop
{
for(j=1;j<=i;j++) //inner loop
{
printf("%d ",j);
}
printf("\n"); //for go to the next line
}
}
Q19(a). Write a C program to generate following triangle up to n lines
* * * *
* * *
* *
*
#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter the number of rows: "); scanf("%d", &rows);
for (i = rows; i >= 1; --i) { for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
Q20(a). Write a C program to generate following triangle up to n
lines. [15 Marks]
1
2 3
4 5 6
#include <stdio.h>
int main()
{
int rows, i, j, number = 1; printf("Enter the number of rows: "); scanf("%d", &rows);
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= i; ++j)
{
printf("%d ", number);
++number;
}
printf("\n");
}
}
Q21(a). Write a C program to generate following triangle up to n lines.
A A B
A B C
#include <stdio.h>
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
printf("%c ", 'A' + j - 1);
}
printf("\n");
}
}
OR
#include<stdio.h>
int main()
{
int i,j,n;
printf("Enter the no of lines\n"); scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%c ",(char)(j+64));
}
printf("\n");
}
}
Q22(a). Write a C program to generate following triangle up to n lines.
A
B C
A B A
#include<stdio.h>
void main()
{
int i,j,n;
printf("Enter the no of lines\n"); scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i+1;j++)
{
printf("%c ",(char)(j+64));
}
printf("\n");
}
}

0 Comments
Please do not enter any spam link in the comment box.