Wednesday, 7 June 2023

C Programming Chapter 1

C PROGRAMS

Chapter 1


1.1.            Write a program to show a message only.

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

printf(“Technologica \nComputer \nEducation \nSociety”);

getch();

}

 

1.2 Write a program to addition of two numbers

#include<stdio.h>

#include<conio.h>

 void main()

{

  int a, b, c;

  clrscr();

  printf(“Enter the 1st number: “);

  scanf(“%d”,&a);

  printf(“Enter the 2ndnumber: “);

  scanf(“%d”,&a);

  c=a+b;

                 printf(“\nAddition: %d”,c);

                 getch(); 

}

 

1.3 Write a program to calculation of two numbers

#include<stdio.h>

#include<conio.h>

 void main()

  {

  int a,b,c,d,e;

  float f;

  clrscr();

  printf(“Enter the 1st number: “);

  scanf(“%d”,&a);

  printf(“Enter the 2nd number: “);

  scanf(“%d”,&b);

  c=a+b;

  d=a-b;

  e=a*b;

  f=a/b;

  printf(“\nAddition: %d”,c);

  printf(“\nSubtraction: %d”,d);

  printf(“\nMultiplication: %d”,e);

  printf(“\nDivsion: %f”,f);

  getch();

  }

 

1.4 Write a program to add three numbers.

#include<stdio.h>

#include<conio.h>

void  main()

          {

          int a,b,c,d;

          clrscr();

          printf(“Enter the 1st Number”);

          scanf(“%d”,&a);

printf(“Enter the 2nd Number”);

          scanf(“%d”,&b);

          printf(“Enter the 3rd Number”);

          scanf(“%d”,&c);

          d=a+b+c;

          printf(“Addition = %d”,d);

          getch();

          }

 

1.5 Write a program to calculate the area and circumference of a circle.

 

#include<stdio.h>

#include<conio.h>

void main()

          {

          float r,cir,area;

          clrscr();

          printf(“ Enter the radius”);

          scanf(“%f”,&r);

          area=r*r*22/7;

          cir=2*r*22/7;

          printf(“\n area = %.2f”, area);

          printf(“\n C\circumference = %.2f”, cir);

          getch();

          }

 

1.6 Write a program to calculate the area and perimeter of a rectangle.

#include<stdio.h>

#include<conio.h>

void main()

          {

          float l,b,area,peri;

          clrscr();

          printf(“ Enter the Length”);

          scanf(“%f”,&l);

printf(“ Enter the Width”);

          scanf(“%f”,&b);

          area=l*b;

          peri=2*(l+b);

          printf(“\n Area = %.2f”, area);

          printf(“\n Perimeter = %.2f”, peri);

          getch();

          }

 

 

1.7 Write a program to calculate the distance covered by a wheel in Kilometer if the radius in centimeter is given through the keyboard.

#include<stdio.h>

#include<conio.h>

void main()

  {

  float r,a,c,rot,dis;

  clrscr();

  printf("enter radius (cm)");

  scanf("%f",&r);

  printf("enter rotation");

  scanf("%f",&rot);

  c=2*r*22/7;

  dis=c*rot/100000;

  printf("Circumference in  cm=%.2f",c);

  printf("distance covered in km=%.2f",dis);

  getch();

  }

 

1.8 Write a program to calculate total cost for coloring a room if height, width, length and color rate is given through the keyboard.

#include<stdio.h>

#include<conio.h>

void main()

          {

float h,w,l,cr,ta,tc;

clrscr();

printf("Enter the Length (feet)");

scanf("%f",&l);

printf("Enter the Width (feet)");

scanf("%f",&w);

printf("Enter the Height (feet)");

scanf("%f",&h);

printf("Enter the Rate for the Coloring as Per Square feet");

scanf("%f",&cr);

ta=(2*(l*h))+(2*(w*h))+(w*l);

tc=ta*cr;

printf("Total Area %.2f\n",ta);

printf("Total Cost %.2f\n",tc);

getch();

          }

 

1.9 Write a program to calculate the distance in Hectometer, Decameter, Meter, Decimeter, Centimeter, Millimeter, Inch, Feet and Gauge if it is entered as in Kilometer.

#include<stdio.h>

#include<conio.h>

void main()

          {

float km,hm=0,dcm=0,m=0,dm=0,cm=0,mm=0,in=0,ft=0,g=0;

clrscr();

printf("Enter the distance in Kilometer (KM)");

scanf("%f",&km);

hm=km*10;

dcm=hm*10;

m=dcm*10;

dm=m*10;

cm=dm*10;

mm=cm*10;

in=cm/2.54;

ft=in/12;

g=ft/3;

printf(" Distance in Kilometer = %f",km);

printf(" Distance in Hectometer  = %f",hm);

printf(" Distance in Decameter = %f",dcm);

printf(" Distance in Meter = %f",m);

printf(" Distance in Decimeter = %f",dm);

printf(" Distance in Centimeter = %f",cm);

printf(" Distance in Millimeter = %f",mm);

printf(" Distance in inch = %f",in);

printf(" Distance in Feet = %f",ft);

printf(" Distance in Gouge = %f",g);

getch();

          }

 

1.10 Write a program to calculate the retail price for a product if the name and rate and quantity are given through the keyboard.

#include<stdio.h>

#include<conio.h>

void main()

          {

char pn[20];

float r=0,t=0,qty=0,cc=0,vat=0,p=0,rp=0;

printf(" Enter the product name");

scanf("%s",pn);

printf(" Enter the rate");

scanf("%f",&r);

printf(" Enter the Quantity");

scanf("%f",&qty);

t= r*qty;

cc=t*.1;

vat=t*.05;

p=t*.35;

rp=t+cc+vat+p;

printf("\n Retail Price = Rs. %.2f",rp);

getch();

}

 

 

1.11 Write a program to calculate estimated population on a certain period.

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

          {

float p,r,t,a,b,ci;

clrscr();

printf("Enter the current population of the area,rate,time");

scanf("%f%f%f",&p,&r,&t);

a=1+r/100;

b=pow(a,t);

ci= p*b;

printf("The Estimated Population = %.2f", ci);

getch();

          }

 

1.12 Write a program to calculate the discount on a product.

#include<stdio.h>

#include<conio.h>

void main()

          {

char pn[20];

float p=0,dis=0,rp=0;

clrscr();

printf("Enter the Product name");

scanf("%s",pn);

printf("Enter the Prise in Rs.");

scanf("%f",&p);

printf("Enter the Discount Percentage (%)");

scanf("%f",&dis);

rp=p-(p*dis/100);

printf("The current price in Rs. = %f", rp);

getch();

}

1.13 Write a program to calculate the simple interest and final amount  if principal, interest rate and time in years are given through the keyboard.

#include<stdio.h>

#include<conio.h>

void main()

          {

          float p,r,t,si,amt;

          clrscr();

          printf("Enter the Principal Amount");

          scanf("%f",&p);

          printf("Enter the Rate %");

          scanf("%f",&r);

          printf("Enter the Time in years");

          scanf("%f",&t);

          si=p*r*t/100;

          amt=si+p;

          printf("\nThe Simple Interest = Rs.  %.2f",si);

          printf("\nThe Final Amount = Rs.  %.2f",amt);

          getch();

          }

1.14 Write a program to calculate the simple interest and final amount with installment facilities  if principal, interest rate and time in years are given through the keyboard.

 

#include<stdio.h>

#include<conio.h>

void main()

          {

          float p,r,t,si,amt,y,m,d;

          clrscr();

          printf(“Enter the Principal Amount”);

          scanf(“%f”,&p);

          printf(“Enter the Rate %”);

          scanf(“%f”,&r);

          printf(“Enter the Time in years”);

          scanf(“%f”,&t);

          si=p*r*t/100;

          amt=si+p;

          y=amt/t;

          m=y/12;

          d=y/365.25;

          printf(“\nThe Simple Interest = Rs.  %.2f”,si);

          printf(“\nThe Final Amount = Rs.  %.2f”,amt);

printf(“\nThe Yearly Installment = Rs.  %.2f”,y);

printf(“\nThe Monthly Installment = Rs.  %.2f”,m);

printf(“\nThe Daily Installment = Rs.  %.2f”,d);

getch();

          }

 

1.15 Write a program if input is 1 then output is 0 if input is 0 output is 1

                   #include<stdio.h>

#include<conio.h>

void main()

{

int a,b;

clrscr();

printf("enter the no");

scanf("%d",&a);

b=1-a;

printf("result=%d",b);

getch();

}

 

1.16 Write a program to create a salary sheet

#include<stdio.h>

#include<conio.h>

 void main()

  {

  int basic;

  float da,ta,hra,it,pf,gp,np;

  clrscr();

  printf(“Enter the basic salary: “);

 scanf(“%d”,&basic);

 da=basic*0.45;

 ta=basic*0.30;

 hra=basic*0.20;

 it=basic*0.04;

 pf=basic*0.08;

 gp=basic+da+ta+hra;

 np=gp-it-pf;

 printf(“\nBasic salary is: %d”,basic);

 printf(“\nD.A. is: %.2f”,da);

 printf(“\nT.A. is: %.2f”,ta);

 printf(“\nH.R..A. is: %.2f”,hra);

 printf(“\nI.T. is: %.2f”,it);

 printf(“\nP.F. is: %.2f”,pf);

  printf(“\nG.P. is: %.2f”,gp);

  printf(“\nN.P. is: %.2f”,np);

  getch();

  }

 

1.17 Write a program to convert Celsius to Fahrenheit

 

#include<stdio.h>

#include<conio.h>

 void main()

  {

  float f,c;

  clrscr();

  printf("Enter the celsius: ");

  scanf("%f",&c);

  f=(9*c+160)/5;

  printf("\nFahrenheit: %.2f",f);

  getch();

  }

1.18 Write a program to convert Fahrenheit to Celsius

#include<stdio.h>

#include<conio.h>

 void main()

  {

  float f,c;

  clrscr();

  printf("Enter fahrenheit: ");

  scanf("%f",&f);

  c=(5*f-160)/9;

  printf("\nCelsius: %.2f",c);

  getch();

  }

 

1.19 Write a C program to find largest among three numbers using conditional operator.

#include<stdio.h>

#include<conio.h>

void main()

{

inta,b,c,d;

clrscr();

printf("Enter the three number: ");

scanf("%d %d %d",&a,&b,&c);

d=(a>b?(a>c?a:c):b>c?b:c);

printf("\nThe large number is: %d",d);

getch();

 }

 

1.20 Write a C program for swapping of two numbers.

#include<stdio.h>

#include<conio.h>

void main()

 {

int a,b,c;

clrscr();

printf("Enter the numbers for swap: ");

scanf("%d %d",&a,&b);

 c=a;

 a=b;

 b=c;

printf("\nSwaped result is: %d %d",a,b);

getch();

 }

 

1.21 Write a C program for swapping of two numbers without using a third variable.  

#include<stdio.h>

#include<conio.h>

void main()

 {

inta,b;

clrscr();

printf("Enter the numbers for swap: ");

scanf("%d %d",&a,&b);

 a=a+b;

 b=a-b;

 a=a-b;

printf("\nSwaped result is: %d %d",a,b);

getch();

    }

1.22  If a five digit number is input through the keyboard, write a program to reverse the number.

 

#include<stdio.h>

#include<conio.h>

void main()

{

long  int  a ,b=0;

clrscr();

printf(“Enter the five digit number”);

scanf(“%ld”,&a);

b=b*10+a%10;

a=a/10;

b=b*10+a%10;

a=a/10;

b=b*10+a%10;

a=a/10;

b=b*10+a%10;

a=a/10;

b=b*10+a%10;

a=a/10;

printf(“The Reverse of the Number = %ld”,b);

getch();

}

 

1.23  If a four digit number is input through the keyboard, write a program to the sum of the first and last digit of this number.

 

#include<stdio.h>

#include<conio.h>

void main()

{

long int a,b=0,m,n,x;

clrscr();

printf(“Enter the five digit number”);

scanf(“%ld”,&a);

b=a%10;

a=a/10;

m=b;

b=a%10;

a=a/10;

b=a%10;

a=a/10;

b=a%10;

a=a/10;

b=a%10;

a=a/10;

n=b;

x=n+m;

printf(“The sum of the first and last digit = %ld”,x);

getch();

}

 

1.24  In a town, the percentage of men is 52. The percentage of total literacy is 48. If total percentage of literate men is 35 of the total population, write a program to find the total number of illiterate men and women if the population of the town is 80,000.

#include<stdio.h>

#include<conio.h>

void main()

          {

          long int totop=80000;

          long int totmen, totlit, ilitmen, totwomen, totlitwomen, ilitwomen;

          clrscr();

          totmen=(52.0/100.0)*totpop;

          printf(“\n Total number of men in the town is : %ld”,totmen);

          totlit=(48.0/100.0)*totpop;

          printf(“\n Total number of literate in the town is : %ld”,totlit);

          litmen=(35.0/100.0)*totpop;

          printf(“\n Total number of literate men in the town is : %ld”,totmen);

          totlitwomen=totlit-litmen;

totwomen=totpop-totmen;

ilitmen=totmen-litmen;

ilitwomen=totwomen-totlitwomen;

printf(“\n Total number of women id : %ld”,totwoman);

printf(“\n Total number of illiterate men is : %ld”,ilitmen);

printf(“\n Total number of illiterate women is : %ld”,ilitwomen);

printf(“\n\n\n\n\n Press any key to exit..”);

getch();

}

1.25  A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is input through the keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the withdrawer.

#include<stdio.h>

#include<conio.h>

void main()

          {

          int  amount, nohun, nofifty, noten;

          clrscr();

          printf(“Enter the amount to be withdrawn”);

          scanf(“%d”,&amount);

          nohun=amount/100;

amount=amount%100;

nofifty=amount/50;

amount=amount%50;

noten=amount/10;

printf(“\n Number of hundred notes required =  %d”,nohun);

printf(“\n Number of fifty notes required =  %d”,nofifty);

printf(“\n Number of ten notes required = %d”,noten);

printf(“\n\n\n\n\n Press any key to exit …..”);

getch();

          }

1.26  If the total selling price of 15 items and the total profit earned on them is input through the keyboard, write a program to find the cost price of one item.

#include<stdio.h>

#include<conio.h>

void main()

          {

          float sp,cp,profit;

          clrscr();

          printf(“\n Enter the total selling price and profit: “);

          scanf(“%f%f”,&sp,&profit);

          cp=sp-profit;

          cp=cp/15;

          printf(“ Cost Price per item is Rs. %f”,cp);

          printf(“\n\n\n\n Press any key to exit….”);

          getch();

          }

1.27 if a five –digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example if that number is input is 12391 the output should be displayed as 23402.

#include<stdio.h>

#include<conio.h>

void main()

          {

          int  num,a,n;

          long int newnum=0;

          clrscr();

          printf(“\n Enter a 5 digit number (less than 32767)”);

          scanf(“%d”,&num);

a=num/10000+1;

n=num % 10000;

newnum=newnum+a*10000L;

 

a=n/1000+1;

n=n % 1000;

newnum=newnum+a*1000;

 

a=n/100+1;

n=n % 100;

newnum=newnum+a*100;

 

a=n/10+1;

n=n % 10;

newnum=newnum+a*10;

 

a=n+1;

newnum= newnum +a ;

 

printf(“\n The new numbers are %d”,newnum);

getch();

          }

                  

 

No comments:

Post a Comment

JAVA PROGRAMMING - OOPS CHAPTER 1

Object-Oriented Programming Chapter 1: Basics by Souradeep Roy Using IntelliJ IDEA Community version:- _____________________________________...