0% found this document useful (0 votes)
17 views24 pages

Gaurav. Com

The document contains a series of programming tasks and their corresponding C code implementations by Gaurav Sharma, a student with roll number 2025195. Each task includes input prompts and output results for various mathematical and logical problems, such as calculating areas, determining gross salary, evaluating functions, and checking for prime numbers. The document also includes user-defined functions for games and checks for Armstrong numbers.

Uploaded by

arjungupta200620
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views24 pages

Gaurav. Com

The document contains a series of programming tasks and their corresponding C code implementations by Gaurav Sharma, a student with roll number 2025195. Each task includes input prompts and output results for various mathematical and logical problems, such as calculating areas, determining gross salary, evaluating functions, and checking for prime numbers. The document also includes user-defined functions for games and checks for Armstrong numbers.

Uploaded by

arjungupta200620
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

/*

NAME : GAURAV SHARMA


UNIVERSITY ROLL NO. : 2025195
SECTION :G
Q1. The length & breadth of a rectangle and radius of a circle are input through the
keyboard. Write a program to calculate the area & perimeter of the rectangle, and the
area & circumference of the circle.
*/

#include <stdio.h>
int main()
{
float l,b,r,pie=3.14;
printf("\t\t\t*****INPUT*****\n\n");
printf("Length of rectangle is ");
scanf("%f", &l);
printf("Breadth of rectangle is ");
scanf("%f", &b);
float a=l*b;
float p=2*(l+b);
printf("Radius of circle is ");
scanf("%f", &r);
float ac= pie*r*r;
float cc= 2*pie*r;
printf("\n\t\t\t*****OUTPUT*****\n\n");
printf("Area of rectangle is %.2f m2\nPerimeter of rectangle is %.2f m", a,p);
printf("\nArea of circle is %.2f m2\nCircumference of the circle is %.2f m", ac,cc);
return 0;
}
*****INPUT*****

Length of rectangle is 45
Breadth of rectangle is 85
Radius of circle is 26

*****OUTPUT*****

Area of rectangle is 3825.00 m2


Perimeter of rectangle is 260.00 m
Area of circle is 2122.64 m2
Circumference of the circle is 163.28 m

*****INPUT*****

Length of rectangle is 4
Breadth of rectangle is 8
Radius of circle is 12

*****OUTPUT*****

Area of rectangle is 32.00 m2


Perimeter of rectangle is 24.00 m
Area of circle is 452.16 m2
Circumference of the circle is 75.36 m

*****INPUT*****

Length of rectangle is 60
Breadth of rectangle is 20
Radius of circle is 45
*****OUTPUT*****

Area of rectangle is 1200.00 m2


Perimeter of rectangle is 160.00 m
Area of circle is 6358.50 m2
Circumference of the circle is 282.60 m
/*
NAME : GAURAV SHARMA
UNIVERSITY ROLL NO. : 2025195
SECTION :G
Q2. Mr. X’s basic salary is input through the keyboard. If the basic salary exceeds
50000, his dearness allowance is 30% of the basic salary, and the house rent allowance is
15% of basic salary otherwise his dearness allowance is 20% of the basic salary, and the
house rent allowance is 10% of basic salary. Write a program to calculate his gross
salary.
*/

#include <stdio.h>
int main()
{
float bs,da,hr;
printf("\t\t\t*****INPUT*****\n\n");
printf("Basic Salary of Mr. X is ");
scanf("%f", &bs);
printf("\n\t\t\t*****OUTPUT*****\n\n");
if(bs>50000)
{
da=bs+.3*bs;
hr=bs+.15*bs;
printf("Gross salary of Mr. X is %.2f rupees.", bs+da+hr);
}
else
{
da=bs+.2*bs;
hr=bs+.1*bs;
printf("Gross salary of Mr. X is %.2f rupees.", bs+da+hr);
}
return o;
}
*****INPUT*****

Basic Salary of Mr. X is 400000

*****OUTPUT*****

Gross salary of Mr. X is 1380000.00 rupees.

*****INPUT*****

Basic Salary of Mr. X is 1425369

*****OUTPUT*****

Gross salary of Mr. X is 4917523.13 rupees.

*****INPUT*****

Basic Salary of Mr. X is 65000

*****OUTPUT*****

Gross salary of Mr. X is 224250.00 rupees.


/*
NAME : GAURAV SHARMA
UNIVERSITY ROLL NO. : 2025195
SECTION :G
Q3. The following calculates value of f(x) if x has different ranges of value as below:
F(x) =x2+2 if 0<=x<=10
F(x) =x2+2x if 11<=x<=20
F(x) =x3+2x2 if 21<=x<=30
F(x) =0 if x>30
*/

#include <stdio.h>
int main()
{
int x,f;
printf("\t\t\t*****INPUT*****\n\n");
printf("X=");
scanf("%d", &x);
if(x>=0 && x<=10)
f=x*x + 2;
else if(x>=11 && x<=20)
f=x*x + 2*x;
else if(x>=21 && x<=30)
f=x*x*x + 2*x*x;
else
f=0;
printf("\n\t\t\t*****OUTPUT*****\n\n");
printf("F(x) = %d", f);
return 0;
}
*****INPUT*****

X=3

*****OUTPUT*****

F(x) = 11

*****INPUT*****

X=66

*****OUTPUT*****

F(x) = 0

*****INPUT*****

X=27

*****OUTPUT*****

F(x) = 21141
/*
NAME : GAURAV SHARMA
UNIVERSITY ROLL NO. : 2025195
SECTION :G
Q4. Write a program to input a three-digit number and print it in words using switch
case.
Sample input 256
Output: Two Five Six
*/

#incude <stdio.h>
int main()
{
int num,d1,d2,d3;
printf("\t\t\t*****INPUT*****\n\n");
scanf("%d", &num);
d1=num/100;
d2=(num/10)%10;
d3=num%10;
printf("\n\t\t\t*****OUTPUT*****\n\n");
switch(d1)
{
case 1: printf("One "); break;
case 2: printf("Two "); break;
case 3: printf("Three "); break;
case 4: printf("Four "); break;
case 5: printf("Five "); break;
case 6: printf("Six "); break;
case 7: printf("Seven "); break;
case 8: printf("Eight "); break;
case 9: printf("Nine "); break;
default: break;
}
switch(d2)
{
case 0: printf("zero "); break;
case 1: printf("one "); break;
case 2: printf("two "); break;
case 3: printf("three "); break;
case 4: printf("four "); break;
case 5: printf("five "); break;
case 6: printf("six "); break;
case 7: printf("seven "); break;
case 8: printf("eight "); break;
case 9: printf("nine "); break;
default: break;
}

switch(d3)
{
case 0: printf("zero"); break;
case 1: printf("one "); break;
case 2: printf("two "); break;
case 3: printf("three "); break;
case 4: printf("four "); break;
case 5: printf("five "); break;
case 6: printf("six "); break;
case 7: printf("seven "); break;
case 8: printf("eight "); break;
case 9: printf("nine "); break;
default: break;
}
return 0;
}
*****INPUT*****

Enter Three Digit Number: 125

*****OUTPUT*****

One two five

*****INPUT*****

Enter Three Digit Number: 555

*****OUTPUT*****

Five five five

*****INPUT*****

Enter Three Digit Number: 785

*****OUTPUT*****

Seven eight five


/*
NAME : GAURAV SHARMA
UNIVERSITY ROLL NO. : 2025195
SECTION :G
Q5. Consider the below series:
0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8
This series is a mixture of 2 series all the odd terms in this series form even numbers in
ascending order and every even terms is derived from the previous term using the
formula (x/2). Write a program to find the nth term in this series.
*/

#include <stdio.h>
int main()
{
int num ,i,k;
printf("\t\t\t*****INPUT*****\n\n");
printf("Term:");
scanf("%d", &num);
for(i=0;i<num;i++)
{
if(i%2==0)
k=i/2;
}
printf("\n\t\t\t*****OUTPUT*****\n\n");
if(num%2==0)
printf("Term is %d", k);
else
printf("Term is %d", 2*k);
return 0;
}
*****INPUT*****

Term:12

*****OUTPUT*****

Term is 5

*****INPUT*****

Term:24

*****OUTPUT*****

Term is 11

*****INPUT*****

Term:11

*****OUTPUT*****

Term is 10
/*
NAME : GAURAV SHARMA
UNIVERSITY ROLL NO. : 2025195
SECTION :G
Q6. Write a program to print the sum of given series: 1!+2!-3!+4!-5!..................n!
*/

#include <stdio.h>
int main()
{
int num,i,j;
printf("\t\t\t*****INPUT*****\n\n");
printf("Number of terms =");
scanf(%d",&num);
int sum=0;
for(i=1;i<=num;i++)
{
int fact=1;
for(j=1;j<=i;j++)
fact=fact*j;
if (i>1 && i%2==1)
fact=fact*-1;
sum=sum+fact;
}
printf("\n\t\t\t*****OUTPUT*****\n\n");
printf("Sum of series is %d",sum);
return 0;
}
*****INPUT*****

Number of terms =6

*****OUTPUT*****

Sum of series is 621

*****INPUT*****

Number of terms =10

*****OUTPUT*****

Sum of series is 3301821

*****INPUT*****

Number of terms =2

*****OUTPUT*****

Sum of series is 3
/*
NAME : GAURAV SHARMA
UNIVERSITY ROLL NO. : 2025195
SECTION :G
Q7. Write a program to print all the prime numbers between a given range p and q.
*/

#include <stdio.h>
int main()
{
int q,p,i,j,c=0;
printf("\t\t\t*****INPUT*****\n\n");
printf("Enter starting range:");
scanf("%d",&p);
printf("Enter ending range:");
scanf("%d",&q);
printf("\n\t\t\t*****OUTPUT*****\n\n");
for(i=p+1;i<q;i++)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
printf("%d\n",i);
}
return 0;
}
*****INPUT*****

Enter starting range:12


Enter ending range:59

*****OUTPUT*****

13
17
19
23
29
31
37
41
43
47
53

*****INPUT*****

Enter starting range:56


Enter ending range:89

*****OUTPUT*****

59
61
67
71
73
79
83

*****INPUT*****

Enter starting range:125


Enter ending range:200

*****OUTPUT*****

127
131
137
139
149
151
157
163
167
173
179
181
191
193
197
199
/*
NAME : GAURAV SHARMA
UNIVERSITY ROLL NO. : 2025195
SECTION :G
Q8. Write a user defined function to create a game where a player will get a chance to
input three numbers from keyboard with his eyes closed. Check if the sum of the input
numbers is odd or even. If sum is even then ask him to play again and for every chance
give one point. If he can score three points (continuous three times got even sum),
declare him winner and print “you won” otherwise print “you lost.” Print the result in
main.
*/

#include <stdio.h>
int main()
{
int a,b,c,pts=0,i;
printf("\t\t\t*****INPUT*****\n\n");
for(i=3;i>0;i--)
{
printf("Enter first number: ");
scanf("%d",&a);
printf("Enter second number: ");
scanf("%d",&b);
printf("Enter third number: ");
scanf("%d",&c);
if((a+b+c)%2==0)
{
pts++;
if(pts<3)
printf("Correct, enter digits again\n");
}
else
{
printf("\n\t\t\t*****OUTPUT*****\n\n");
printf("You lose");
break;
}
}
if(pts==3)
{
printf("\n\t\t\t*****OUTPUT*****\n\n");
printf("You win");
}
return 0;
}
*****INPUT*****

Enter first number: 56


Enter second number: 4
Enter third number: 8
Correct, enter digits again
Enter first number: 15
Enter second number: 48
Enter third number: 56

*****OUTPUT*****

You lose

*****INPUT*****

Enter first number: 2


Enter second number: 5
Enter third number: 7
Correct, enter digits again
Enter first number: 5
Enter second number: 7
Enter third number: 1

*****OUTPUT*****

You lose

*****INPUT*****

Enter first number: 2


Enter second number: 2
Enter third number: 8
Correct, enter digits again
Enter first number: 6
Enter second number: 8
Enter third number: 2
Correct, enter digits again
Enter first number: 4
Enter second number: 1
Enter third number: 5

*****OUTPUT*****

You win
/*
NAME : GAURAV SHARMA
UNIVERSITY ROLL NO. : 2025195
SECTION :G
Q9. Write a code to input a number and check if it is an Armstrong number or not?
(number can have any number of digits)
*/

#include <stdio.h>
int main()
{
int num;
printf("\t\t\t*****INPUT*****\n\n");
printf("Enter number:");
scanf("%d",&num);
int original=num;
int c=0;
while(num>0)
{
num=num/10;
c++;
}
num=original;
int sum=0;
while(num>0)
{
int r=num%10;
int z=pow(r,c);
sum=sum+z;
num=num/10;
}
printf("\n\t\t\t*****OUTPUT*****\n\n");
printf("%d",sum);
if(sum==original)
printf("\nNumber is Armstrong Number. ");
else
printf("\nNumber is not Armstrong Number. ");
return 0;
}
*****INPUT*****

Enter number:345

*****OUTPUT*****

216
Number is not Armstrong Number.

*****INPUT*****

Enter number:1634

*****OUTPUT*****

1634
Number is Armstrong Number.

*****INPUT*****

Enter number:36

*****OUTPUT*****

45
Number is not Armstrong Number.

You might also like