Gaurav. Com
Gaurav. Com
#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*****
*****INPUT*****
Length of rectangle is 4
Breadth of rectangle is 8
Radius of circle is 12
*****OUTPUT*****
*****INPUT*****
Length of rectangle is 60
Breadth of rectangle is 20
Radius of circle is 45
*****OUTPUT*****
#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*****
*****OUTPUT*****
*****INPUT*****
*****OUTPUT*****
*****INPUT*****
*****OUTPUT*****
#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*****
*****OUTPUT*****
*****INPUT*****
*****OUTPUT*****
*****INPUT*****
*****OUTPUT*****
#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*****
*****INPUT*****
*****OUTPUT*****
*****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*****
*****OUTPUT*****
13
17
19
23
29
31
37
41
43
47
53
*****INPUT*****
*****OUTPUT*****
59
61
67
71
73
79
83
*****INPUT*****
*****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*****
*****OUTPUT*****
You lose
*****INPUT*****
*****OUTPUT*****
You lose
*****INPUT*****
*****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.