Practicals

This Page provides the solution of various practicals of Fundamental of computer programming



Write a program to calculate Simple Interest SI = (P * R * N)/100; Where, P = principle amount, R = Rate of interest, N = Period.

// Program to calculate Simple interest

#include<stdio.h>
#include<conio.h>
void main()
{
      int P,R,N;
      float SI;

      //Enters value of Principal amount Rate and Periods (Input Section)

      printf("Enter value"); /*This line is not medentory its only
                  used for your redablilty to pass inputs*/

      scanf("%d%d%d",&P,&R,&N); //Variables are case sensitive P and p both are diffrent

      // After passing inputs write logic if any
      // In this programme logic is to calculate Simple Interest

      SI=(P*R*N)/100;  //Logic

      //After logic display the value into the screen (Output Section)
      printf("Simple Rate is %f",SI);
      getch();

}

 Write a program to compute a volume of a cylinder. Use symbolic constant.

#include<stdio.h>
#include<conio.h>
#define PI 3.1472    // Capital is not compulsory but you should                          //you capital latter in #define statement
void main()
{
  int r,h;
  float V;
  clrscr(); // Clear previous screen

  //Input value of r and h by scanf function

  scanf("%d%d",&r,&h);

  //Wirte down logic

  V=PI*r*r*h;
  printf("\t***********************************");
  printf("\n\tVolume of Cylinder is %f\n",V);
  printf("\t***********************************");

  getch();     // Holds the o/p screen untill you pass key from keyboard


}


Write a program to interchange value of two variables.
a)      Using third variable
b)      Without using third variable

#include<stdio.h>
#include<conio.h>
void main()
{
  int a=10,b=20,c=0;
  clrscr();

  //No need of input Because we have already assigned it at compile time

  //Logic of Swapping with 3 variable

  c=a;
  a=b;
  b=c;

  // Logic of Swapping without 3rd variable

/*     a=a+b;
  b=a-b;
  a=a-b;*/

  printf("After swapping value of a and b is %d and %d respectively",a,b);
  getch();

}


Write a program to calculate Net Salary. User has to input Basic Salary and Output should be:
Enter Basic Salary: 5000 (e.g. 5000)
Allowances:
                        DA = 70% of Basic Salary
HRA = 7% of Basic Salary
MA = 2% of Basic Salary
TA = 4% of Basic Salary
            Deduction:
                        PF = 12% of Basic Salary
                        IT = any value (e.g. 500)
            ----------------------------------------------------------------------------------------------
            Net Salary = Basic Salary + Allowances – Deduction

#include<stdio.h>
#include<conio.h>
void main()
{
int basic,it=500;

float da,ta,hra,ma,pf,net_salary; // net-salary and net salary is not allowed
clrscr();
basic=21600; //input
// Calculate allowances (It will be added into basic salary)
da=(basic*70.0)/100.0;
hra=(basic*7.0)/100.0;
ma=(basic*2.0)/100.0;
ta=(basic*2.0)/100.0;
//Calculate PF
pf=(basic*12.0)/100.0;

net_salary=basic+da+hra+ma+ta-it-pf;
printf("%f",net_salary);
getch();
}

Write a program which scans the age in years and prints it in seconds.

#include<stdio.h>
#include<conio.h>
 main()
{
     int age;
     long int second= 1314000;
                /* here if you going to convert age into second you
                have to take data type of second as long int because
                range of the int variable is from -32768 to 32767. So
                it may possible that value of second wiil be exceed to 32767*/
//   clrscr();
     age=1;
     second=age*365*60*60;
     printf("\t%ld",second); //control string for long int is %ld
       //  printf("  %d",sizeof(long int));

     //getch();
}





Write a program to print the ASCII value of a given character and vice-versa.

#include<stdio.h>
#include<conio.h>
void main()
{
int number;
char ch;
ch='A';
clrscr();
printf("ASCII value of given character is %d",ch);

number=66;
printf("\n\n%d has equivalent ASCII value is %c",number,number);

getch();
}








2 comments: