Programming for problem solving using C language
Simple programs for practice-1
By
Smt. Venkata Sushma chinta
1.WAP to swap two numbers
Sample Input :
Enter two numbers
3
48
Sample Output:
Before swapping a=3 and b=48
After swapping a=48 and b=3
2.WAP to find simple interest and compound
interest.
Sample Input :
Enter the principle amount
200000
Enter time period in years
2
Enter rate of interest
12
Enter frequency of compounding
2
Sample output:
The simple interest= 48000.00
The compound interest= 52495.34
3.WAP to find the sum of digits of a three digit
number.
Sample Input :
Enter a three digit number
123
Sample Output :
The sum of the digits of 123 is 6
4.WAP to convert the temperature in Fahrenheit to degrees
Celsius
Sample Input :
Enter a temperature in Fahrenheit
212
Sample Output :
Celsius temperature= 100.00
5. Write a C program to convert a given integer (in days) to years, months and days,
assumes that all months have 30 days and all years have 365 days.
Sample Input :
Enter no.of days
2536
Sample Output :
6 year(s)
11 months(s)
16 day(s)
6. Income Calculation:
In a company named Micky software solution, many part-time employees are working for a pay of
Rs. 100 per hour. Write a program to calculate the total amount an employee earns in a year by
working part time. Consider employees should work all day in the year and year has 365 days.
Sample Input :
Enter no of hours worked in a day
3
Sample Output :
Total income in a year is 109500
7. Compute Gain Percentage
Vikram buys an old scooter for Rs. A and spends Rs. B on its repairs. If he sells the scooter for Rs. C ,
What is the gain %?
Sample Input :
Price of old scooter:
4700
The amount spent for repair:
800
Sold Price:
5800
Sample Output :
Gain percentage is 5.45
8. Display Characters
Rohan wants a magic board, which displays a character for a corresponding number for his science exhibition. Help him
to develop such application.
For example when the digits 65,66,67,68 are entered, the alphabet ABCD are to be displayed.
• Sample Input :
Enter the digits:
65
66
67
68
• Sample Output :
65-A
66-B
67-C
68-D
1.WAP to swap two numbers
#include<stdio.h>
int main()
{
int a,b,temp;
printf("enter two numbersn");
scanf("%d%d",&a,&b);
printf("Before swapping a=%d and b=%dn",a,b);
temp=a;
a=b;
b=temp;
printf("After swapping a=%d and b=%dn",a,b);
return 0;
}
2.WAP to find simple interest and compound interest.
/*program to find simple interest and compound interest*/
#include<stdio.h>
#include<math.h>
int main()
{
float p,t,r,n,si,ci;
printf("Enter principle amountn");
scanf("%f",&p);
printf("Enter time period in yearsn");
scanf("%f",&t);
printf("Enter rate of interestn");
scanf("%f",&r);
printf("Enter compounding frequencyn");
scanf("%f",&n);
si=(p*t*r)/100.0;
ci=p*(pow(1+r/(100*n),n*t)-1);
printf("The simle interest = %.2f nThe compound interest=
%.2fn",si,ci);
}
3.WAP to find the sum of digits of a three digit number.
/*program to find the sum of the digits of a 3 digit number*/
#include<stdio.h>
int main()
{
int n,ld,sd,fd,sum,t;
printf("enter a three digit numbern");
scanf("%d",&n);
t=n;
ld=n%10;
n=n/10;
sd=n%10;
fd=n/10;
sum=fd+sd+ld;
printf("the sum of the digits of %d is %dn",t,sum);
return 0;
}
4.WAP to convert the temperature in Fahrenheit to degrees
Celsius
/* to convert the temperature in Fahrenheit to degrees Celsius*/
#include<stdio.h>
int main()
{
float fah, cel;
printf("Enter a temperature in Fahrenheitn");
scanf("%f", &fah);
cel = (5.0/9) * (fah - 32);
printf("Celsius temperature= %.2f n", cel);
return 0;
}
5. Write a C program to convert a given integer (in days) to years,
months and days, assumes that all months have 30 days and all years
have 365 days.
#include <stdio.h>
int main()
{
int n,y,m,d,x;
printf("Enter no. of days: ");
scanf("%d", &n);
y =n/365;
x=n%365;
m=x/30;
d=x%30;
printf(" %d Year(s) n %d Month(s) n %d Day(s)",y,m,d);
return 0;
}
6. Income Calculation:
In a company named Micky software solution, many part-time employees are working for a pay of
Rs. 100 per hour. Write a program to calculate the total amount an employee earns in a year by
working part time. Consider employees should work all day in the year and year has 365 days.
/*Income calculation*/
#include <stdio.h>
int main()
{
int h,ai;
printf("Enter no of hours worked in a dayn");
scanf("%d",&h);
ai=100*h*365;
printf("Total income in a year is %dn",ai);
return 0;
}
7. Vikram buys an old scooter for Rs. A and spends Rs. B on its
repairs. If he sells the scooter for Rs. C , What is the gain %?
/*Gain percentage*/
#include <stdio.h>
int main()
{
float p,r,s,tc,g;
printf("Price of the old scooter:n");
scanf("%f",&p);
printf("The amount spent for repair:n");
scanf("%f",&r);
printf("Sold price:n");
scanf("%f",&s);
tc=p+r;
g=(s-tc)/tc*100;
printf("Gain percentage is: %.2fn",g);
return 0;
}
8. Display Characters
Rohan wants a magic board, which displays a character for a corresponding number for his science exhibition.
Help him to develop such application.
For example when the digits 65,66,67,68 are entered, the alphabet ABCD are to be displayed.
/*Display Characters for numbers*/
#include <stdio.h>
int main()
{
int n1,n2,n3,n4;
printf("Enter digits n");
scanf("%d%d%d%d",&n1,&n2,&n3,&n4);
printf("%d-%cn",n1,n1);
printf("%d-%cn",n2,n2);
printf("%d-%cn",n3,n3);
printf("%d-%cn",n4,n4);
return 0;
}

programming for programs solving using C language

  • 1.
    Programming for problemsolving using C language Simple programs for practice-1 By Smt. Venkata Sushma chinta
  • 2.
    1.WAP to swaptwo numbers Sample Input : Enter two numbers 3 48 Sample Output: Before swapping a=3 and b=48 After swapping a=48 and b=3
  • 3.
    2.WAP to findsimple interest and compound interest. Sample Input : Enter the principle amount 200000 Enter time period in years 2 Enter rate of interest 12 Enter frequency of compounding 2 Sample output: The simple interest= 48000.00 The compound interest= 52495.34
  • 4.
    3.WAP to findthe sum of digits of a three digit number. Sample Input : Enter a three digit number 123 Sample Output : The sum of the digits of 123 is 6
  • 5.
    4.WAP to convertthe temperature in Fahrenheit to degrees Celsius Sample Input : Enter a temperature in Fahrenheit 212 Sample Output : Celsius temperature= 100.00
  • 6.
    5. Write aC program to convert a given integer (in days) to years, months and days, assumes that all months have 30 days and all years have 365 days. Sample Input : Enter no.of days 2536 Sample Output : 6 year(s) 11 months(s) 16 day(s)
  • 7.
    6. Income Calculation: Ina company named Micky software solution, many part-time employees are working for a pay of Rs. 100 per hour. Write a program to calculate the total amount an employee earns in a year by working part time. Consider employees should work all day in the year and year has 365 days. Sample Input : Enter no of hours worked in a day 3 Sample Output : Total income in a year is 109500
  • 8.
    7. Compute GainPercentage Vikram buys an old scooter for Rs. A and spends Rs. B on its repairs. If he sells the scooter for Rs. C , What is the gain %? Sample Input : Price of old scooter: 4700 The amount spent for repair: 800 Sold Price: 5800 Sample Output : Gain percentage is 5.45
  • 9.
    8. Display Characters Rohanwants a magic board, which displays a character for a corresponding number for his science exhibition. Help him to develop such application. For example when the digits 65,66,67,68 are entered, the alphabet ABCD are to be displayed. • Sample Input : Enter the digits: 65 66 67 68 • Sample Output : 65-A 66-B 67-C 68-D
  • 10.
    1.WAP to swaptwo numbers #include<stdio.h> int main() { int a,b,temp; printf("enter two numbersn"); scanf("%d%d",&a,&b); printf("Before swapping a=%d and b=%dn",a,b); temp=a; a=b; b=temp; printf("After swapping a=%d and b=%dn",a,b); return 0; }
  • 11.
    2.WAP to findsimple interest and compound interest. /*program to find simple interest and compound interest*/ #include<stdio.h> #include<math.h> int main() { float p,t,r,n,si,ci; printf("Enter principle amountn"); scanf("%f",&p); printf("Enter time period in yearsn"); scanf("%f",&t); printf("Enter rate of interestn"); scanf("%f",&r); printf("Enter compounding frequencyn"); scanf("%f",&n); si=(p*t*r)/100.0; ci=p*(pow(1+r/(100*n),n*t)-1); printf("The simle interest = %.2f nThe compound interest= %.2fn",si,ci); }
  • 12.
    3.WAP to findthe sum of digits of a three digit number. /*program to find the sum of the digits of a 3 digit number*/ #include<stdio.h> int main() { int n,ld,sd,fd,sum,t; printf("enter a three digit numbern"); scanf("%d",&n); t=n; ld=n%10; n=n/10; sd=n%10; fd=n/10; sum=fd+sd+ld; printf("the sum of the digits of %d is %dn",t,sum); return 0; }
  • 13.
    4.WAP to convertthe temperature in Fahrenheit to degrees Celsius /* to convert the temperature in Fahrenheit to degrees Celsius*/ #include<stdio.h> int main() { float fah, cel; printf("Enter a temperature in Fahrenheitn"); scanf("%f", &fah); cel = (5.0/9) * (fah - 32); printf("Celsius temperature= %.2f n", cel); return 0; }
  • 14.
    5. Write aC program to convert a given integer (in days) to years, months and days, assumes that all months have 30 days and all years have 365 days. #include <stdio.h> int main() { int n,y,m,d,x; printf("Enter no. of days: "); scanf("%d", &n); y =n/365; x=n%365; m=x/30; d=x%30; printf(" %d Year(s) n %d Month(s) n %d Day(s)",y,m,d); return 0; }
  • 15.
    6. Income Calculation: Ina company named Micky software solution, many part-time employees are working for a pay of Rs. 100 per hour. Write a program to calculate the total amount an employee earns in a year by working part time. Consider employees should work all day in the year and year has 365 days. /*Income calculation*/ #include <stdio.h> int main() { int h,ai; printf("Enter no of hours worked in a dayn"); scanf("%d",&h); ai=100*h*365; printf("Total income in a year is %dn",ai); return 0; }
  • 16.
    7. Vikram buysan old scooter for Rs. A and spends Rs. B on its repairs. If he sells the scooter for Rs. C , What is the gain %? /*Gain percentage*/ #include <stdio.h> int main() { float p,r,s,tc,g; printf("Price of the old scooter:n"); scanf("%f",&p); printf("The amount spent for repair:n"); scanf("%f",&r); printf("Sold price:n"); scanf("%f",&s); tc=p+r; g=(s-tc)/tc*100; printf("Gain percentage is: %.2fn",g); return 0; }
  • 17.
    8. Display Characters Rohanwants a magic board, which displays a character for a corresponding number for his science exhibition. Help him to develop such application. For example when the digits 65,66,67,68 are entered, the alphabet ABCD are to be displayed. /*Display Characters for numbers*/ #include <stdio.h> int main() { int n1,n2,n3,n4; printf("Enter digits n"); scanf("%d%d%d%d",&n1,&n2,&n3,&n4); printf("%d-%cn",n1,n1); printf("%d-%cn",n2,n2); printf("%d-%cn",n3,n3); printf("%d-%cn",n4,n4); return 0; }