//write a program to arithemetic operation in c
#include<stdio.h>
void main()
{
int x,y,ans,choice,a;
char yes='Y';
do
{
printf("!!!!!!!!!!!!!!!!!!!!!!!!!\n");
printf("arithemetic calculator\n");
printf("1.Add\n");
printf("2.sub\n");
printf("3.multi\n");
printf("4.divi\n");
printf("!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
printf("Please enter the choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("Enter the two number to add:\n");
scanf("%d%d",&x,&y);
ans=x+y;
printf("Ans is %d\n",ans);
break;
default: printf("enter choice is invalid\n");
break;
}
printf("\n\n\nDo You Want To Use Again(Y or N)??????\n");
fflush(stdin);
scanf("%c",&yes);
a=1;
}
while(a>6);
printf("Thanking for using it");
}
2.)
#include<stdio.h>
void main()
{
int x,y,ans;
printf("Enter the two number:\n");
scanf("%d%d",&x,&y);
if(ans=x+y)
printf("Ans is %d",ans);
else
{
if(ans=x-y)
printf("Ans is %d",ans);
else
{
if(ans=x*y)
printf("Ans is %d",ans);
else
{
if(ans=x/y)
printf("Ans is %d ",ans);
else
{
printf("Ans is Invalid ");
}
}
}
}
}
3.)
// C program to draw a moving car. This
// program run in gcc compiler having
// graphics.h library installed
#include <stdio.h>
// Function to draw moving car
void draw_moving_car(void) {
int i, j = 0;
// Passed three arguments to initgraph
// function to initialize graphics mode
for (i = 0; i <= 420; i = i + 10) {
// Set color of car as red
// Thease lines for bonnet and
// body of car
line(0 + i, 300, 210 + i, 300);
line(50 + i, 300, 75 + i, 270);
line(75 + i, 270, 150 + i, 270);
line(150 + i, 270, 165 + i, 300);
line(0 + i, 300, 0 + i, 330);
line(210 + i, 300, 210 + i, 330);
// For left wheel of car
circle(65 + i, 330, 15);
circle(65 + i, 330, 2);
// For right wheel of car
circle(145 + i, 330, 15);
circle(145 + i, 330, 2);
// Line left of left wheel
line(0 + i, 330, 50 + i, 330);
// Line middle of both wheel
line(80 + i, 330, 130 + i, 330);
// Line right of right wheel
line(210 + i, 330, 160 + i, 330);
delay(100);
// To erase previous drawn car, draw
// the whole car at same possition
// but color using black
// Lines for bonnet and body of car
line(0 + i, 300, 210 + i, 300);
line(50 + i, 300, 75 + i, 270);
line(75 + i, 270, 150 + i, 270);
line(150 + i, 270, 165 + i, 300);
line(0 + i, 300, 0 + i, 330);
line(210 + i, 300, 210 + i, 330);
// For left wheel of car
circle(65 + i, 330, 15);
circle(65 + i, 330, 2);
// For right wheel of car
circle(145 + i, 330, 15);
circle(145 + i, 330, 2);
// Line left of left wheel
line(0 + i, 330, 50 + i, 330);
// Line middle of both wheel
line(80 + i, 330, 130 + i, 330);
// Line right of right wheel
line(210 + i, 330, 160 + i, 330);
}
getch();
closegraph();
}
// Driver code
int main()
{
draw_moving_car();
return 0;
}
4.)
//write a program to find round off the numbers
//author:upendra
#include<stdio.h>
#include<math.h>
void main()
{
int cel,flr;
float a;
printf("enter the number to round off in ceiling and floor:\n");
scanf("%f",&a);
cel=ceil(a);
flr=floor(a);
printf("Round off value to ceiling is %d\n\n\n",cel);
printf("Round off value to floor is %d",flr);
}
5.)
/* write a program to print
a to z using while loop*/
#include<stdio.h>
void main()
{
char ch='a';
while(ch<='z')
{
printf("%c",ch);
ch++;
}
}
6.)
// write a program to get character ASCII value
// author: upendra date:10/27/2020
#include<stdio.h>
void main()
{
char a,b,c; // a,b,c are character variables
a='70';
b='71';
printf("Character is %c",a,b);
}
7.)
/* write a program to identify whether it is
character or not*/
#include<stdio.h>
void main()
{
char ch; //ch is a character variable
printf("Enter any character :");
scanf("%c",&ch);
if(ch>='a'&&ch<='z')
{printf("it is a alphabet");}
else{
if(ch>='A'&&ch<='Z')
{printf("it is a alphabet");}
else
{printf("it is not a alphabet");}
}
}
8.)
/*switch can also written for char
expression*/
#include<stdio.h>
void main()
{
char ch='z';
switch(ch)
{
case 'a':
printf("this is 'a'");
break;
case 'z':
printf("this is 'z'");
break;
default:
printf("User input is invalid");
}
}
9.)
//write a basic problem on relational operator
//author:upendra
#include<stdio.h>
void main()
{
int a,b,result;
printf("Note: 1=true and 0=false:\n");
printf("Enter the two numbers:\n");
scanf("%d%d",&a,&b);
result=a!=b;
printf("Result is %d",result);
}
10.)
#include<stdio.h>
void main()
{
char yes='Y';
int x,y;
{while(yes=='Y')
printf("Enter two numbers x and y\n");
scanf("%d%d",&x,&y);
printf("%d\n",x+y);
printf("Do you want to continue? press Y- Yes or N- No");
scanf("%c",&yes);
}
}
11.)
#include<stdio.h>
void main()
{
float ar,b,h; // ar is area of a triangle , b is breath of triangle ,h is height
printf("Enter the two values b,h");
scanf("%f%f",b,h);
ar= 1/2(b*h);
printf("Area is %f",ar);
}
#include<stdio.h>
void main()
{
float ar,b,h; // ar is area of a triangle , b is breath of triangle ,h is height
printf("Enter the two values b,h");
scanf("%f%f",b,h);
ar= 1/2(b*h);
printf("Area is %f",ar);
}
12.)// write a program to convert distance b|w the two cities in meter
//inch,centimeter
//author:upendra yadav date:10/27/2020
#include<stdio.h>
void main()
{
int m,cm,km;
float ft,inch;
printf("Enter the distance b|w two cities in Km:\n");
scanf("%d",&km);
m=1000*km;
cm=m*100;
ft=cm/30.48;
inch=cm/2.54;
/* converts following answer is */
printf("the distance b|w two cities in meter is %d\n\n",m);
printf("the distance b|w two cities in Centimeter is %d\n\n",cm);
printf("the distance b|w two cities in Foot is %f\n\n",ft);
printf("the distance b|w two cities in inchs is %f\n\n",inch);
}
13.)
/*write a program to find the no. of a note in amount
*/
#include<stdio.h>
void main()
{
int amount;
printf("Enter the total amount:\n");
scanf("%d",&amount);
if(amount==500)
printf("500:");
else{
if(amount==100)
printf("100:");
else
{
if(amount==50)
printf("50:");}}}
14.)
#include<stdio.h>
squa(float);
void main()
{
float x,y;
printf("Enter the one value to square:\n");
scanf("%f",&x);
y=squa(x);
printf("answer is %f",y);
}
squa(float a)
{
float ans;
ans=a*a;
return ans;
}
15.)
/* write a program where number is divisible
3 or 4 or not */
#include<stdio.h>
void main()
{int year;
printf("enter a year:");
scanf("%d",&year);
if(year%4==0)
{
printf("year is a leap year");
}
else
{
printf("year is not leap year");
}
}
16.)
#include<stdio.h>
void main()
{
int a=0;
do
{
printf("system is hacked m'aam");
}
while(a>-1);
}
17.)
//write a program to calculate electricity bill
#include<stdio.h>
void main
{
int units;//units-electricity,surcharge-20%
float Rupees; //rupees in rupees
printf("Enter the Electricity Units:\n");
scanf("%d",units);
if(units<=50)
Rupees=0.50*units;
printf("Electricity amount is %f",Rupees);
else
{
if(units<=150)
Rupees=0.75*units;
printf("Electricity amount is %f",Rupees);
else
if(units<=250)
Rupees=1.20*units;
printf("Electricity amount is %f",Rupees);
else
if(units>=250)
Rupees=1.50*units;
printf("Electricity amount is %f",Rupees);
}
}
18.)
//write a program for elctricity bill calculation
//if sur_charge if 20%
#include<stdio.h>
void main()
{
int units;
float amt,sur_charge,total_amt;
printf("Enter the units consumed:\n");
scanf("%d",&units);
if(units<=50)
{
amt=0.50*units;
}
else if(units<=150)
{
amt=25+((units-50)*0.75);
}
else if(units<=250)
{
amt=100+((units-150)*1.20);
}
else if(units>=250)
{
amt=220+((units-250)*1.50);
}
sur_charge=amt*0.20;
total_amt=sur_charge+amt;
printf("Your this months Electricity Bill is %2f",total_amt);
}
No comments:
Post a Comment