Subscribe

RSS Feed (xml)

Monday, March 8, 2010

Write a C program to find the greatest common divisor (GCD) of the two given positive integers.

#include< stido.h>
#include< conio.h>
int main( )
{
int a, b, res;
clrscr( );
printf("Enter the two integer values:");
scanf("%d%d", &a, &b);

for( ; ; ) //This is empty for loop.
{
res = a%b;
if( res = = 0) break;
a = b;
b = res;
}
printf("\n The GCF is : %d", res);
getch( );
return 0;
}

Write a C program that prints a given positive integer in reverse order and also sum of the individual digits involved in the given integer.

#include< stdio.h>
#include< conio.h>
int main( )
{
int no, rev=0, rem, sum=0;
clrscr( );
printf("Enter the required integer:");
scanf("%d", &no);
while(no>0)
{
rem = no%10;
rev = (10*rev)+rem;
sum = sum+rem;
no=no/10;
}
printf("\nReverse Number : %d", rev);
printf("\nSum of the individual digits : %d", sum);
getch( );

return 0;
}

Note: If any compile errors, please mail to me..

Write a C program to find the commission on a salesman's total sales

Full Question:
                      The commission on a salesman’s total sales is as follows:
a) If sales <100, then there is no commission.

b) If 100>= sales <=500, then commission = 10% of sales.

c) If sales > 500, then commission = 100+8% of sales above 500

Solution:-

#include< stdio.h>
#include< conio.h>
int main( )
{
int sales;
float comm;
clrscr( );
printf("Enter the total sales:");
scanf("%d", &sales);
if(sales<100)
printf("\nSorry no Commission, please do more sales");
else if(sales>=100 && sales<=500)
printf("\nCommission : %f ", (sales*0.1));
else
{
comm=(sales-500)*0.08;
printf("\nCommission : %f ", (comm+100));
}
getch( );
return 0;
}