Wednesday 6 February 2013

ALL C Programs with Codes

ALL C Programs with Codes
http://www.engineersgarage.com/c-language-programs?page=1


/* PROGRAM FOR ELIGIBLETY */
/* Admission to a professional course is number of if statements
   (a) Marks in Maths >=60
   (b) Marks in Phy >=50
   (a) Marks in Chem>=40
   (a) Total in all three subject >=200
       or
       Total in Math and Subjects >=150
       given the marks in the three subjects, write a program to
       process the application to list the eligi candidate
*/

#include<stdio.h>
#include<conio.h>
void main()
{  
    int p,c,m,t,mp;
    clrscr();
    printf("Enter the marks obtained in phy chem & maths\n");
    scanf("%d%d%d",&p,&c,&m);
    
    if (m<60 || p<50 || c<40)
        goto end;
   
    t=p+c+m;
    mp=m+p;
    if (t>=200 || mp>=150)
        printf("This candidate is eligible\n");
    else
       end:
       printf("This candidate is not eligible\n");
   getch();
}

Find the simple interest , given principle rate of interest and times

/* Write a C program to find the simple interest , given principle, *

 * rate of interest and times*/
#include <stdio.h>
#include <conio.h>
void main()
{
   float p, r, si;
   int t;
   clrscr();
   printf("Enter the values of p,r and t\n");
   scanf ("%f %f %d", &p, &r, &t);
   si = (p * r * t)/ 100.0;
  
   printf ("Amount = Rs. %5.2f\n", p);
   printf ("Rate   = Rs. %5.2f%\n", r);
   printf ("Time   = %d years\n", t);
   printf ("Simple interest  = %5.2f\n", si);
}
/*-----------------------------
Output
Enter the values of p,r and t
2000
8
3
Amount = Rs. 2000.00
Rate   = Rs.  8.00%
Time   = 3 years
Simple interest  = 480.00
------------------------------*/

Calculate Total Marks, Percentage and Division of a Student

* Q.NO. - 21 PROGRAM READ ROLL NO NAME OF STUDENT AND THREE
              SUBJECT MARKS THROUGH KEY BOARD AND CALCULATE TOTAL,PER,DIV */




#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    int rl,phy,che,ca,total;
    float per;
    char nm[20],div[10];
    clrscr();
    printf("Enter the Roll Number of the student \t");
    scanf("%d",&rl);
    printf("\nEnter the Name of Students  \t");
    scanf("%s",nm);
    printf("\nEnter the phy chem ca marks  \t");
    scanf("%d%d%d",&phy,&che,&ca);
    total = phy+che+ca;
    per = total/3.0;
    if (per>=60)
         strcpy(div,"First");
    else
        if (per<60&&per>=48)
            strcpy(div,"Second");
        else
            if (per<48&&per>=36)
                strcpy(div,"Pass");
             else
                strcpy(div,"Fail");




       printf("\nRoll No : %d\nName of Student : %s\n",rl,nm);
       printf("Phy Marks = %d\nChem Marks = %d\nCom Appli = %d\n",phy,che,ca);
       printf("Total Marks = %d\nPercentage = %5.2f\nDivision = %s\n",total,per,div);
       getch();
    getch();
}

Print Electricity Bill of a Customer

/* Q.N. 20
   Write a program to print the Electricity bill of a given customer.
   The program should read customer idno., name and unit consumed by
   the user and print the total amount to pay. The charge are as under
   if unit <200 then charge are @ Rs. 1.20 per unit
   if unit >=200 but <400 then charge are @ Rs. 1.60 per unit
   if unit >=400 but <600 then charge are @ Rs. 2.00 per unit
   if unit >=600 then charge are @ Rs. 2.50 per unit
   If bill exceed Rs. 300 then a surcharge of 15% will be charged
   and minimum bill should be of Rs. 25/-.  */
 
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{  int cust_no, unit_con;
   float charge,surcharge=0, amt,total_amt;
   char nm[25];
   clrscr();
   printf("enter the customer IDNO :\t");
   scanf("%d",&cust_no);
   printf("\nenter the customer Name :\t");
   scanf("%s",nm);
   printf("\nenter the unit consumed by customer  :\t");
   scanf("%d",&unit_con);
   if (unit_con <200 )
        charge = 1.20;
   else      if (unit_con>=200 && unit_con<400)
                charge = 1.60;
        else if (unit_con>=400 && unit_con<600)
                       charge = 2.00;
                else
                       charge = 2.50;
   amt = unit_con*charge;
   if (amt>300)
        surcharge = amt*15/100.0;
   total_amt = amt+surcharge;
   if (total_amt  < 25)
        total_amt =25;
   clrscr();
   printf("\t\t\tElectricity Bill\n\n");
   printf("Customer IDNO                         :\t%5d",cust_no);
   printf("\nCustomer Name                       :\t%s",nm);
   printf("\nunit Consumed                       :\t%5d",unit_con);
   printf("\nAmount Charges @Rs. %4.2f  per unit :\t%8.2f",charge,amt);
   printf("\nSurchage Amount                     :\t%8.2f",surcharge);
   printf("\nNet Amount Paid By the Customer     :\t%8.2f",total_amt);
   getch();}

Display month name according to the month number using Switch Statement

/* read any Month Number (int) display Month name in word  */
/* use of switch statement */
#include<stdio.h>
#include<conio.h>
void main()
{
   int n;
   clrscr();
   printf("Month No:-> ");
   scanf("%d",&n);
   switch(n)
   {
        case 1:
               printf("January\n");
               break;
        case 2:
               printf("February\n");
               break;
        case 3:
               printf("March\n");
               break;
        case 4:
               printf("April\n");
               break;
        case 5:
               printf("MAy\n");
               break;
        case 6:
               printf("June\n");
               break;
        case 7:
               printf("July\n");
               break;
        case 8:
               printf("August\n");
               break;
        case 9:
               printf("September\n");
               break;
        case 10:
               printf("October\n");
               break;
        case 11:
               printf("November\n");
               break;
        case 12:
               printf("December\n");
               break;
        default:
               printf("invalid Month number\nPlease try again ....\n");
               break;
      }
   getch();
}
 

Print a table of given number

* QN 22  PROGRAM PRINT A TABLE OF GIVEN NUMBER  */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
char ans = 'Y';
while(ans =='y' ||ans =='Y')
{
        clrscr();
        printf("enter the number which table to be generate  \n");
        scanf("%d",&n);
        for (i=1;i<=10;i++)
                printf("%3d * %2d =  %4d\n",n,i,n*i);
        getch();
 
        printf("do yoy want to continue .......<y/n> ?\n");
        ans =getche();
}
}



No comments:

Post a Comment