Showing posts with label Getting Started with C. Show all posts
Showing posts with label Getting Started with C. Show all posts

Thursday, 2 August 2012

Basic C Programming014

Input a character from user and print its ASCII value.


#include <stdio.h>
#include <conio.h>
void main ( )
{
          char       x;
          clrscr ( );
                     
          printf ("\n\n\n\t\t Input a character..:"); scanf ("%c",&x);
            
          printf("\n\n\n\t\t ASCII value of '%c' is %d", x, x);
          getch ( );
}

Click here to contact us 

Tuesday, 31 July 2012

Basic C Programming013

Input two numbers and swapping these two numbers without using third variable.


#include <stdio.h>
#include <conio.h>
void main( )
{
       int        m,n;
       clrscr ( );
                          
       printf ("\n\n\t\t Enter first number...:"); scanf ("%d",&m);
       printf ("\n\n\t\t Enter second number..:"); scanf ("%d",&n);
                 
       m = m + n;
       n = m - n;
       m = m - n;
                           
       printf ("\n\n\n\t\t\t After Swapping \n\t\t_____________________________ \n");
       printf ("\n\t\t The first number is...: %d \n\n\t\t The second number is..: %d",m,n);
               
       getch ( );
}
Click here to contact us

Basic C Programming012


Write a program that calculates the net salary using entered basic salary.
Here, D.A. = 27%, H.R.A. = 10%, P.F. = 12% of basic salary; and M.A. = Rs.100, T.A.= Rs.1600 are fixed and I.T. = Rs.1000. Net salary = basic salary + (DA + HRA + MA + TA) - (PF + IT)
A program should print the output in the following format only:

ENTER BASIC SALARY (in Rs.) =40000
                  ALLOWANCES:
                  D.A. =10800.00
                  H.R.A. = 4000.00
                  M.A. = 100.00
                  T.A. = 1600.00
                  DEDUCTION:
                  P.F. = 4800.00
                  I.T. = 1000.00
-------------------------------------------
        NET SALARY = 50700.00


#include <stdio.h>
#include <conio.h>
void main ( )
{
        float      basic, da, hra, ma, ta, pf , it, net;
        clrscr( );
               
        printf ("\n\n\n\t\t ENTER BASIC SALARY (in Rs.)="); scanf("%f",&basic);
             
        da = ( basic * 27 ) / 100;
        hra = ( basic * 10 ) / 100;
        pf = ( basic * 12 ) / 100;
        ma = 100;
        ta = 1600;
        it = 1000;
        net = ( basic + da + hra + ma + ta) - ( pf + it );
                        
        printf ("\n\t\t\t ALLOWANCES: \n\t\t\t______________ \n");
        printf ("\n\t\t\t D.A.=%.2f",da);
        printf ("\n\t\t\t H.R.A.=%.2f",hra);
        printf ("\n\t\t\t M.A.=%.2f",ma);
        printf ("\n\t\t\t T.A.=%.2f",ta);
        printf ("\n\n\t\t\t DEDUCTION:\n");
       printf ("\n\t\t\t P.F.=%.2f",pf);
       printf ("\n\t\t\t I.T.=%.2f",it);
       printf ("\n\t\t\t___________________\n");
       printf("\n\t\t\t NET SALARY=%.2f",net);
          
       getch( );
}

Click here to contact us

Sunday, 29 July 2012

Basic C Programming011

Write a function that takes time in seconds as input and prints it in terms of hours, minutes and seconds.


#include<stdio.h>
#include<conio.h>
void main( )
{
        int         sec, hr = 0, min = 0;
     
        clrscr( );
        printf("\n Enter the time in seconds..:"); scanf("%d",&sec);
     
        min = sec / 60;
        sec = sec % 60;
        hr = min / 60;
        min = min % 60;
     
        printf("\n The time is %d hr: %d min: %d sec",hr,min,sec);
        getch();
}
Click here to contact us 

Thursday, 5 July 2012

Basic C Programming010

In a town, the percentage of men is fifty two. The percentage of total literacy is forty eighty. If total percentage of literate men is thirty five of the total population, write a program to find the total number of illiterate men and women if the population of the town is eighty thousand. 


#include <stdio.h>
#include <conio.h>
void main ( )
{
         long       tl, lm, ilm, m, w, lw, ilw ,tp = 80000;
         clrscr( );
                          
         m = tp * 52 / 100;                          /* Total men */
         w = tp - m;                                     /* Total women */
         tl = tp * 48 / 100;                           /* Total literacy */
         lm = tp * 35 / 100;                         /* Literate men */
         ilm = m - lm;                                   /* Illiterate men */
         lw = tl - lm;                                     /* Literate women */
         ilw = w - lw;                                   /* Illiterate women */
                 
         printf("\n\n\t\t Total illiterate women= %ld \n\n\n\t\t Total illiterate men= %ld", ilw , ilm);
         getch( );
}
Click here to contact us 

Basic C Programming009

A cashier has currency notes of denominations Ten, Fifty and Hundred. 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 withdraw.  


#include <stdio.h>
#include <conio.h>
void main ( )
{
           int rs, ten, fifty, hun, x, y;
           clrscr ( );
 
           printf("\n Enter amount to withdrawn..:"); scanf("%d",&rs);

           hun = rs / 100;
           x = rs % 100;
           fifty = x / 50;
           y = x % 50;
           ten = y / 10;

           printf("\n\n %d Hundred rupees notes\n\n %d Fifty rupees notes\n\n %d Ten
                        rupees notes",hun,fifty,ten);
           getch ( );
}

Click here to contact us

If the total selling price of fifteen items and the total profit entered on them is input through the keyboard, write a program to fined the cost price of one item.


#include <stdio.h>
#include <conio.h>
void main ( )
{
          float               sprice, tprofit, cprice;
          clrscr( );
        
          printf("\n Selling price of 15 itens..:Rs."); scanf("%f",&sprice);
printf("\n Enter total profit..:Rs."); scanf("%f",&tprofit);

          cprice = (sprice-tprofit)/15;

printf("\nCost price of one item=Rs.%.2f",cprice);
          getch ( );
}

Click here to contact us

Wednesday, 4 July 2012

Basic C Programming008

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

#include <stdio.h>
#include <conio.h>
void main ( )
{
          int       num, p, sum = 0;
          clrscr ( );
                               
          printf ("\n\n\n\t Enter a four digit number...:"); scanf ("%d",&num);
                          
          p = num / 1000;                  /* first digit */
          sum = sum + p;                   /* sum updated with addition of first digit */
          p = num % 10;                    /* last digit */
          sum = sum + p;                   /* sum updated with addition of last digit */
                                           
          printf ("\n\n\n\t Sum of first and last digit of %d is...:%d",num, sum);
          getch ( );
}
Click here to contact us 

Basic C Programming007

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 ( )
{       
          int         num, p;
          long      revnum = 0;
          clrscr ( );
                                  
          printf ("\n\n\n\t Enter a five digit number (less than 32767)...:"); scanf ("%d",&num);
             
          p = num % 10;                                 /* last digit extracted as reminder */
          num = num /10;                                /* remaining digits */
          revnum = revnum + p * 10000L;      /* revnum updated with value of extracted digit */
                                                                    
          p = num % 10;                                 /* fourth digit */
          num = num /10;                                /* remaining digits */
          revnum = revnum + p * 1000;                          
                                                                                          
          p = num % 10;                                 /* third digit */
          num = num /10;                                /* remaining digits */
          revnum = revnum + p * 100;                     
                                                                                         
          p = num % 10;                                 /* second digit */
          num = num /10;                                /* remaining digits */
          revnum = revnum + p * 10;                               
                                                                                                 
          p = num % 10;                                 /* first digit */
          revnum = revnum + p;
                              
          printf ("\n\n\n\t The reversed number is...:%ld", revnum);
          getch ( );
}
 Click here to contact us 

Basic C Programming006

If a five digit number is input through the key board, write a program to calculate the sum of its digits.
[ Use the modulus operator ' % ' . The division operator ' / ' , returns the quotient on dividing one number by another, whereas the modulus operator ' % ' gives the remainder on dividing one number by another. For example {m = 14 % 2 would store 0 in m } { m = 16 % 3 would store 1 in m } ]


#include <stdio.h>
#include <conio.h>
void main ( )
{     
        int       num, p, q, sum = 0;
        clrscr ( );
                 
        printf ("\n\n\n\t Enter a five digit number (less than 32767)...:"); scanf ("%d",&num);
                 
        p = num % 10;                       /* last digit extracted as reminder */
        q = num /10;                          /* remaining digits */
        sum = sum + p;                                                     
                                                                                                     
        p = q % 10;                           /* fourth digit */
        q = q /10;                                                      
        sum = sum + p;                                                     
                                                                     
        p = q % 10;                           /* third digit */
        q = q /10;                                           
        sum = sum + p;                                   
                                                                        
        p = q % 10;                           /* second digit */
        q = q /10;                                                           
        sum = sum + p;                                               
                                                                       
        p = q % 10;                           /* first digit */
        sum = sum + p;
                       
        printf ("\n\n\t The Sum of the five digits of %d is.....:%d", num, sum);
        getch ( );
}
Click here to contact us 

Tuesday, 3 July 2012

Basic C Programming005

The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area and circumference of the circle.

#include <stdio.h>
#include <conio.h>
void main ( )
{
        int          l, b, r, area1, peri;
        float       area2, circum, p=3.14;
        clrscr ( );
                      
        printf ("\n Enter the length breadth of Rectangle : -"); scanf ("%d %d",&l, &b);
        printf ("\n Enter the radius of Circle : -"); scanf ("%d",&r);   
                                    
        area1 = l * b;
        peri = 2 * ( l + b );
        area2 = p * r * r;
        circum = 2 * p * r;
                                     
        printf ("\n Area of Rectangle : - %d", area1);
        printf ("\n Perimeter of Rectangle : - %d", peri);
        printf ("\n Area of Circle : - %f", area2);
        printf ("\n Circumference of Circle : - %f", circum);
        getch ( );
}


Click here to contact us

Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.

#include <stdio.h>
#include <conio.h>

void main ( )
{
        int       p, q, r;
        clrscr ( );
             
        printf ("\n Enter the number at location C : -"); scanf ("%d",&p);
        printf ("\n Enter the number at location D : -"); scanf ("%d",&q);
                 
        r = p;
        p = q;
        q = r;
                     
        printf ("\n New number at location C : - %d", p);
        printf ("\n New number at location D : - %d", q);
        getch ( );
}

Click here to contact us 

Basic C Programming004


Input distance in kilometers and write a program to convert this distance in meters, feet, inches and centimeters. 

#include <stdio.h>
#include <conio.h>
void main ( )
{
         float     km, m, cm, ft, inch;
         clrscr ( );
                    
         printf ("\n Enter the distance in kilometers : -"); scanf ("%f",&km);
                      
         m = km * 1000;
         cm = m * 100;
         inch = cm / 2.54;
         f t= inch / 12;
                              
         printf ("\n Distance in meters : - %f", m);
         printf ("\n Distance in centimeters : - %f", cm);
         printf ("\n Distance in inches : - %f", inch);
         printf ("\n Distance in feet : - %f", ft);
         getch ( );
}
A student get marks in eight different subjects are input through keyboard, find out the total marks and percentage marks get by the student. Assume that the maximum marks that can be get by a student in each subject is hundred.   

 #include <stdio.h>
#include <conio.h>
void main ( )
{
         int        m1, m2, m3, m4, m5, m6, m7, m8, tot;
         float    per;
         clrscr ( );
        
         printf ("\n Enter marks in eight different subject : -");
         scanf ("%d %d %d %d %d %d %d %d",&m1, &m2, &m3, &m4, &m5, &m6, &m7, &m8);
               
         tot = m1 + m2 + m4 + m5 + m6 + m7 + m8;
         per = tot / 8;
              
         printf ("\n Total marks is : - %d", tot);
         printf ("\n Percentage is : - %f", per);
         getch ( );


Click here to contact us 

Monday, 2 July 2012

Basic C Programming003

Calculate the Ten, Twenty and Thirty percent of an input number.

 #include <stdio.h>
#include <conio.h>
void main ( )
{
        float       x, p, q, r;
        clrscr ( );
                        
        printf ("\n Enter a number : -"); scanf ("%f",&x);
                 
        p = ( x * 10 ) / 100;
        q = ( x * 20 ) / 100;
        r = ( x * 30 ) / 100;
                                       
        printf ("\n Ten percent of entered number is : - %f", p);
        printf ("\n Twenty percent of entered number is : - %f", q);   
        printf ("\n Thirty percent of entered number is : - %f", r);
        getch ( );


Click here to contact us 

David Smit's basic pay is input through the keyboard. His dearness allowance is forty percent of basic pay, and house rent allowance is twenty percent of basic pay. So calculate his gross pay. 

#include <stdio.h>
#include <conio.h>
void main( )
{
        float      bp, da, hra, grpay;
        clrscr ( );
                         
        printf ("\n Enter the basic pay of David Smit : -"); scanf ("%f",&bp);
                            
        da = 0.4 * bp;
        hra = 0.2 * bp;
        grpay = bp + da + hra;
                    
        printf ("\n Gross pay of David Smit is : - %f", grpay);
        getch ( );


Click here to contact us 

Basic C Programming002


Fahrenheit to Centigrade conversion.

#include <stdio.h>
#include <conio.h>
void main ( )
{
        float       c, f ;
        clrscr ( );
                       
        printf ("\n Enter the temperature in Fahrenheit : -"); scanf ("%f",&f);
                           
        c = ( ( f - 32 ) * 5 ) / 9;
                     
        printf ("\n Temperature in Centigrade is : - %f", c);
               
        getch ( );
Centigrade to Fahrenheit conversion. 

 #include <stdio.h>
#include <conio.h>

void main ( )
{
         float       c, f ;
         clrscr ( );
                     
         printf ("\n Enter the temperature in Centigrade : -"); scanf ("%f",&c);
                         
         f = ( c * 9 + 160 ) / 5;
                      
         printf ("\n Temperature in Fahrenheit is : - %f", f);
                      
         getch ( );
}

Basic C Programming001

Square, Cube, and Fourth of an input number.

#include <stdio.h>
#include <conio.h>

void main ( )
{
        int x, m, n, p;
        clrscr ( );
            
        printf ("\n Enter a number: -"); scanf ("%d",&x);
                 
        m = x * x;
        n = x * x * x;
        p = x * x * x * x;
                    
        printf ("\n Square of the entered number : - %d", m);
        printf ("\n Cube of the entered number : - %d", n);
        printf ("\n Fourth of the entered number : - %d", m);
        getch ( );
}

Click here to contact us

Area of a Circle.

#include <stdio.h>
#include <conio.h>

void main ( )
{
        float r, a, p = 3.14 ;
        clrscr ( );
             
        printf ("\n Enter the radius of a circle : -"); scanf ("%f",&r);
                
        a = r * r * p;
                
        printf ("\n The area of Circle is : - %f", a);
        getch ( );
}

Click here to contact us 

Basic C Programming

Add two numbers

#include <stdio.h>
#include <conio.h>
void main ( )
{
        int a,b,c;
        clrscr ( );
                     
        printf ("\n\n\n\t\t Enter 1st number...:"); scanf ("%d",&a);
        printf ("\n\n\t\t Enter 2nd number...:"); scanf ("%d",&b);
                       
        c = a + b;
                             
        printf ("\n\n\t\t The Sum is....: %d", c);
        getch ( );
}

Click here to contact us

Sum and Average of three numbers

#include <stdio.h>
#include <conio.h>
void main( )
{
       int a,b,c,d=0,e;
       clrscr ( );
         
       printf ("\n Enter 1st number: -"); scanf ("%d",&a);
       printf ("\n Enter 2nd number: -"); scanf ("%d",&b);
       printf ("\n Enter 3rd number: -"); scanf ("%d",&c);
            
       d = a + b + c;
       e = d/3;
                
       printf ("\n The Sum is: - %d", d);
       printf ("\n The Average is: - %d", e);
       getch ( );
Related Posts Plugin for WordPress, Blogger...