File

advertisement
1. Write a program to convert a length from kilometers to meters.
2. Write a program to divide an integer by another integer and find the quotient and
remainder.
3. Write a program to convert entered number of days into years, months and days.
4. Write a program to convert seconds to hours, minutes and seconds and print them one
below the other. For example if 357 seconds is given, the output must be : 0 hours 5
minutes 57seconds
5. Write a program to read the principal, rate of interest and number of years and find the
simple interest using the formula simple interest=pnr/100.
6. If a cube has its side and its volume and surface area given by the formulae v = a3 and s=6a2.
Write a program to read ‘a’ and print the volume and surface area.
7. The area of a triangle is given by the formula area =1/2 base *height. Write a program to
read base and height and print the area.
8. Write a program to find the area of a circle(a=22/7*r2)
9. Write a program to find the volume of the cylinder. (v=22/7*r2h)
10. Write a program to convert a temperature reading in degree Fahrenheit to degree Celsius
using the formula:
C= (5/9)*(f-32).
11. Write a program to input an arbitrary number and find out whether it is positive, or
negative.
12. Write a program to decide whether there is gain or loss; when cost price (CP) and selling
price (SP) of items are given.
13. Write a program to input any three integer numbers and display the largest number.
14. Write a program to calculate area of a circle, a rectangle or a triangle depending upon user’s
choice.
15. Write a program to enter the day, month and year of the date of birth of a person and the
day, month and year of today and find the age of the person in years, months and days.
16. Write a program to enter marks for English, Hotel management, Marketing, Accountancy
and Computer. Calculate total and percentage. Find the division.
17. Write a program to display the multiplication table of an entered number.
18. Write a c program to print Fibonacci series i.e.0 1 1 2 3 5 8….. up to the nth term
19. Write a program to check whether the given number is palindrome or not.
20. Write a program to find factorial of a given positive number.
21. Write a C program to input an integer and check whether it is Prime or not.
22. For any integer input through the keyboard, write a C program to find out whether it is an
odd number or even number. (HSEB-2062)
23. Write a program to display the name of the day in a week, depending on the number
entered through the keyboard using the switch-case statement.
24. Write a program to reverse a number
25. Write a program to find the sum of the series: 1/12+1/22+1/32+…..1/n2.
26. Write a program to input an integer numbers and find the highest number among them.
27. Write a ‘C’ program to store n numbers in an array and find the smallest number among
them.
28. Write a program to input a string and count the number of vowels containing in the string.
29. Write a C program to input the ages of ‘n’ students and count the number of students who
has the age in between 17-19.
30. Write a ‘C’ program to store a string and determine whether it is palindrome or not.
31. Write a ‘C’ program to find the sum of first ‘n’ natural numbers using recursive function.
32. Write a ‘C’ program to find the factorial of a number using recursive function.
33. A man is paid at the hourly rate of Rs.50/-per hour for the first 30 hours worked in a week.
There after the overtime is paid at 1.5 times the hourly rate for the next time 25 hours and 2
times the hourly rate for further hours worked. Input the number of hours worked in a week
and print weekly wages.
34. Write a program to store marks of ‘n’ students of a class in single dimensional array and find
highest, lowest and average mark of the class and also count the number of students who
obtained marks greater than 60.
35. Write a program to generate Fibonacci series up to nth terms using recursive function.
36. Write a program to stone ‘n’ numbers in an array and sort them in ascending order.
C Solutions ,
1
37. Write a C program to calculate the factorial of given number ‘n’. The rules for calculating are
if n>0 calculate factorial, factorial=1, if n=0 and if n<0, display the error message.
38. National book center decides to prepare a Book Club. Members of the club are entitled to
special discounts on the purchase of the book. The discount of 15% is given to the members
if purchase amount exceeds 5000 and 10% is given it don’t exceed. Non members aren’t
normally given any discount. However if their purchase exceeds Rs. 5000, a discount of 7% is
given. Write a C program to analyze the above problem and find the net purchase amount.
39. Write a program to convert the line of lowercase text to uppercase text.
40. Write a program to print integers from 1 to 100 using WHILE loop
41. Write a program to calculate and print square of any given number.
42. Write a C program to display the sum of ‘n’ terms of even numbers. (HSEB-2063)
43. Write a C program to calculate the factorial of a given number using function. (HSEB-2063)
44. Write a C program to print the first 10 terms of the following series using FOR loop. 1, 5, 9,
13, …….. (HSEB-2063)
45. Write a C program to sort integer values in descending order. (HSEB-2063)
46. Write a C program to read the age of 40 students and count the number of students of the
age between 15 and 25. (HSEB-2063)
47. Write a C program to print the 10 positive integers and their factorials. (HSEB-2062)
48. Write a C program to input ‘n’ numbers and find out greatest and smallest number. (HSEB2062)
49. Write a C program to read in a positive integer less than 20 and display its multiplication
table. (HSEB-2062)
50. Write a C program to input the names of ‘n’ numbers of students and sort them in
alphabetical order. (HSEB-2062)
51. Write a C program to read salaries of 200 employees and count the number of employees
getting salary between 5000 - 10000. (HSEB-2062)
52. Write a C program that will read successive records from the data file and display each
record on the screen in an appropriate format. (HSEB-2062,2061)
53. Write a C program that reads different names and addresses into the computer and
rearrange the names into alphabetical order using the structure variable. (HSEB-2061)
54. Write a C program to display the multiplication table of series of given numbers entered by
the user. (HSEB-2061)
55. Write a program using C language to read the age of 100 persons and count the number of
persons in the age group between 50 and 60. Use the ‘For’ and ‘Continue’ statements.
(HSEB-2061)
56. Write a C program to input a string and count the no of vowels in the string.
57. Write a C program to write the name, address and telno in a data file and read the
successive records to display them in the proper format.
58. Write a C program to write ‘n’ person’s name, address and telno in a data file and display
them, reading the successive data from the file in proper forma
C Solutions ,
2
1. Write a program to convert a length from kilometers to meters.
#include <stdio.h>
#include <conio.h>
void main()
{
int km, m;
clrscr();
printf("Enter the Kilometer:");
scanf("%d",&km);
m=km*1000;
printf("The length in meter=%d",m);
getch();
}
2. Write a program to divide an integer by another integer and find the quotient and
remainder.
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,quo,rem;
clrscr();
printf("Enter two numbers a&b:");
scanf("%d%d",&a,&b);
quo=a/b;
rem=a%b;
printf("Quotient=%d",quo);
printf("\nRemainder=%d",rem);
getch();
}
3. Write a program to convert entered number of days into years, months and days.
#include <stdio.h>
#include <conio.h>
void main()
{
int d,year,month,day,remd;
clrscr();
printf("Enter the number of days to convert:");
scanf("%d",&d);
year=d/365;
remd=d%365;
month=remd/30;
day=remd%30;
printf("Year=%d\nMonth=%d\nDay=%d",year,month,day);
getch();
}
4. Write a program to convert seconds to hours, minutes and seconds and print them one
below the other. For example if 357 seconds is given, the output must be : 0 hours 5
minutes 57seconds
#include <stdio.h>
#include <conio.h>
void main()
{
int s,hour,min,sec,rems;
clrscr();
printf("Enter the seconds to convert:");
scanf("%d",&s);
hour=s/3600;
rems=s%3600;
min=rems/60;
sec=rems%60;
printf("Hour=%d\nMinutes=%d\nSeconds=%d",hour,min,sec);
getch();
C Solutions ,
3
}
5. Write a program to read the principal, rate of interest and number of years and find the
simple interest using the formula simple interest=pnr/100.
#include <stdio.h>
#include <conio.h>
void main()
{
Int p,r,n,I;
clrscr();
printf(“Enter the Principle, Rate and Time:”);
scanf(“%d%d%d”,&p,&r,&n);
i=(p*n*r)/100;
printf(“Interest=%d”,i);
getch();
}
6. If a cube has its side and its volume and surface area given by the formulae v = a3 and s=6a2.
Write a program to read ‘a’ and print the volume and surface area.
#include <stdio.h>
#include <conio.h>
void main()
{
int a,v,s;
clrscr();
printf(“Enter the value of a:”);
scanf(“%d”,&a);
v=a*a*a;
s=6*a*a;
printf(“Volume=%d\nSurface area=%d”,v,s);
getch();
}
7. The area of a triangle is given by the formula area =1/2 base *height. Write a program to
read base and height and print the area.
#include <stdio.h>
#include <conio.h>
void main()
{
int base,height;
float area;
clrscr();
printf(“Enter the base and height:”);
scanf(“%d%d”,&base,&height);
area=(1/2)*base*height;
printf(“Area of the traingle=%f”,area);
getch();
}
8. Write a program to find the area of a circle(a=22/7*r2)
#include <stdio.h>
#include <conio.h>
void main()
{
int r;
float area;
clrscr();
printf(“Enter the radius of the circle:”);
scanf(“%d”,&r);
area=(22/7)*r*r;
printf(“Area of the Circle=%f”,area);
getch();
}
9. Write a program to find the volume of the cylinder. (v=22/7*r2h).
#include <stdio.h>
#include <conio.h>
void main()
C Solutions ,
4
{
int r,h;
float volume;
clrscr();
printf(“Enter the radius and height of the cylinder:”);
scanf(“%d%d”,&r,&h);
volume=(22/7)*r*r*h;
printf(“Volume of the Cylinder=%f”,volume);
getch();
}
10. Write a program to convert a temperature reading in degree Fahrenheit to degree Celsius
using the formula:
C=(5/9)*(f-32).
#include <stdio.h>
#include <conio.h>
void main()
{
int f;
float c;
clrscr();
printf(“Enter the temperature in Fahrenheit:”);
scanf(“%d”,&f);
c=(5/9)*(f-32);
printf(“Temperature in Celsius=%f”,c);
getch();
}
11. Write a program to input an arbitrary number and find out whether it is positive, or
negative.
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
clrscr();
printf(“Enter any number (Either positive or negative):”);
scanf(“%d”,&n);
if(n<0)
printf(“The entered number is negative”);
else
printf(“The entered number is positive”);
getch();
}
12. Write a program to decide whether there is gain or loss; when cost price (CP) and selling
price (SP) of items are given.
#include <stdio.h>
#include <conio.h>
void main()
{
int cp,sp;
clrscr();
printf(“Enter the cost price(cp) and selling price (sp):”);
scanf(“%d%d”,&cp,&sp);
if(sp>cp)
printf(“GAIN”);
else
printf(“LOSS”);
getch();
}
13. Write a program to input any three integer numbers and display the greatest number.
(HSEB-2064)
#include <stdio.h>
#include <conio.h>
void main()
C Solutions ,
5
{
int a,b,c;
clrscr();
printf(“Enter the numbers a, b and c:”);
scanf(“%d%d%d”,&a,&b,&c);
if(a>b && a>c)
printf(“A is the largest number”);
else if(b>a && b>c)
printf(“B is the largest number”);
else
printf(“C is the largest number:”);
getch();
}
14. Write a program to calculate area of a circle, a rectangle or a triangle depending upon user’s
choice.
#include <stdio.h>
#include <conio.h>
void main()
{
char ch;
int r,l,b,base,h;
float area;
clrscr();
printf("Enter the choice, 'c' for circle, 'r' for rectangle or 't' for triangle:");
scanf("%c",&ch);
switch(ch)
{
case 'c':
printf("Enter the radius:");
scanf("%d",&r);
area=(3.14*r*r);
printf("Area of the circle=%f",area);
break;
case 'r':
printf("Enter the length:");
scanf("%d",&l);
printf("Enter the breadth:");
scanf("%d",&b);
area=l*b;
printf("Area of the rectangle=%f",area);
break;
case 't':
printf("Enter the base:");
scanf("%d",&base);
printf("Enter the height:");
scanf("%d",&h);
area=(0.5*base*h);
printf("Area of the triangle=%f",area);
break;
default:
printf("Enter the valid choice, either c,t or r:");
break;
}
getch();
}
15. Write a program to enter the day, month and year of the date of birth of a person and the
day, month and year of today and find the age of the person in years, months and days.
#include <stdio.h>
#include <conio.h>
void main()
{
int td,tm,ty,bd,bm,by,y,rd,m,d,ttd,btd,diff;
clrscr();
printf("Enter your birth date,month,year:");
C Solutions ,
6
scanf("%d%d%d",&bd,&bm,&by);
printf("Enter todays date,month,year:");
scanf("%d%d%d",&td,&tm,&ty);
ttd=ty*365+tm*30+td;
btd=by*365+bm*30+bd;
diff=ttd-btd;
y=diff/365;
rd=diff%365;
m=rd/30;
d=rd%30;
printf("Your Age=%d Year %d Month %d Day",y,m,d);
getch();
}
16. Write a program to enter marks for English, Hotel management, Marketing, Accountancy
and Computer. Calculate total and percentage. Find the division.
#include <stdio.h>
#include <conio.h>
void main()
{
int acc,comp,hm,mkt,eng,total;
float per;
clrscr();
printf("Enter the marks of account:");
scanf("%d",&acc);
printf("\nEnter the marks of Computer:");
scanf("%d",&comp);
printf("\nEnter the marks of Hotel Mgmt:");
scanf("%d",&hm);
printf("\nEnter the marks of Marketing:");
scanf("%d",&mkt);
printf("\nEnter the marks of English:");
scanf("%d",&eng);
total=acc+comp+hm+mkt+eng;
printf("\nTotal=%d",total);
per=total/5;
printf("\nPercentage=%f",per);
if(per>=75)
printf("\nDivision=Distinction");
else if(per>=60)
printf("\nDivision=First Division");
else if(per>=45)
printf("\nDivision=Second Division");
else
printf("\nDivision=Third Division");
getch();
}
17. Write a program to display the multiplication table of an entered number.
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i;
clrscr();
printf("Enter a number:");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
printf("%d*%d=%d\n",n,i,n*i);
}
getch();
}
18. Write a c program to print Fibonacci series i.e.0 1 1 2 3 5 8….. upto nth term.
#include <stdio.h>
#include <conio.h>
C Solutions ,
7
void main()
{
int a=0,b=1,c,n,i;
clrscr();
printf("Enter how many numnbers:");
scanf("%d",&n);
printf("%d,%d",a,b);
for(i=0;i<n-2;i++)
{
c=a+b;
printf(",%d",c);
a=b;
b=c;
}
getch();
}
19. Write a program to check whether the given number is palindrome or not.
#include <stdio.h>
#include <conio.h>
void main()
{
int n,rev=0,digit,num;
clrscr();
printf("Enter a number:");
scanf("%d",&n);
num=n;
while (n!=0)
{
digit=n%10;
rev=rev*10+digit;
n=n/10;
}
if(rev==num)
printf("The number is pallindrome");
else
printf("The number is not a pallindrome");
getch();
}
20. Write a program to find factorial of a given positive number.
#include <stdio.h>
#include <conio.h>
void main()
{
int n,fact,i;
clrscr();
printf("Enter the number");
scanf("%d",&n);
fact=1;
if(n<0)
printf("Factorial of negative number is not possible");
else
{
for(i=n;i>0;i--)
{
fact=fact*i;
}
printf("Factorial=%d",fact);
}
getch();
}
21. Write a C program to input an integer and check whether it is Prime or not.
#include <stdio.h>
#include <conio.h>
C Solutions ,
8
void main()
{
int n,i;
clrscr();
printf("Enter a number:");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
printf("The number is not a prime number:");
getch();
exit(0);
}
}
printf("The number is a prime number");
getch();
}
22. For any integer input through the keyboard, write a C program to find out whether it is an
odd number of even number. (HSEB-2062)
#include <stdio.h>
#include <conio.h>
void main()
{
int num;
clrscr();
printf(“Enter a number”);
scanf(“%d”,&num);
if(num%2==0)
printf(“Even”);
else
printf(“Odd”);
getch();
}
23. Write a program to display the name of the day in a week, depending on the number
entered through the keyboard using the switch-case statement.
#include <stdio.h>
#include <conio.h>
void main()
{
int ch;
clrscr();
printf("Enter a number (1-7) to display the name of the day:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Sunday");
break;
case 2:
printf("Monday");
break;
case 3:
printf("Tuesday");
break;
case 4:
printf("Wednesday");
break;
case 5:
printf("Thursday");
break;
case 6:
printf("Friday");
break;
C Solutions ,
9
case 7:
printf("Saturday");
break;
default:
printf("Enter the valid choice between 1-7");
break;
}
getch();
}
24. Write a program to reverse a number. ( HSEB -2064)
#include <stdio.h>
#include <conio.h>
void main()
{
int n,rev=0,digit;
clrscr();
printf("Enter a number:");
scanf("%d",&n);
while (n!=0)
{
digit=n%10;
rev=rev*10+digit;
n=n/10;
}
printf("Reverse number=%d",rev);
getch();
}
25. Write a program to find the sum of the series: 1/12+1/22+1/32+…..1/n2.
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i;
float sum=0.0;
clrscr();
printf("Enter the last number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+(1/float(i*i));
}
printf("Sum=%f",sum);
getch();
}
26. Write a program to input an integer numbers and find the highest number among them.
#include <stdio.h>
#include <conio.h>
void main()
{
int num[100],n,highest,i;
clrscr();
printf("Enter the value of n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the numbers");
scanf("%d",&num[i]);
}
highest=num[0];
for(i=0;i<n;i++)
{
if(num[i]>highest)
highest=num[i];
}
C Solutions ,
10
printf("The highest number=%d",highest);
getch();
}
27. Write a ‘C’ program to store n numbers in an array and find the smallest number among
them.
#include <stdio.h>
#include <conio.h>
void main()
{
int num[100],n,smallest,i;
clrscr();
printf("Enter the value of n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the numbers");
scanf("%d",&num[i]);
}
smallest=num[0];
for(i=0;i<n;i++)
{
if(num[i]<smallest)
smallest=num[i];
}
printf("The smallest number=%d",smallest);
getch();
}
28. Write a program to input a string and count the number of vowels containing in the string.
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char string[100];
int i, l, count=0;
clrscr();
printf("Enter a String");
scanf("%s",string);
l=strlen(string);
for(i=0;i<l;i++)
{
if(string[i]=='a'||string[i]=='A'||string[i]=='e'||
string[i]=='E'||string[i]=='i'||string[i]=='I'||
string[i]=='o'||string[i]=='O'||string[i]=='u'||
string[i]=='U')
count=count+1;
}
printf("No of Vowels =%d",count);
getch();
}
29. Write a C program to input the ages of ‘n’ students and count the number of students who
has the age in between 17-19.
#include <stdio.h>
#include <conio.h>
void main()
{
int i,n,count=0,age[100];
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the age of student");
C Solutions ,
11
scanf("%d",&age[i]);
}
for(i=0;i<n;i++)
{
if(age[i]>=17 && age[i]<=19)
count=count+1;
}
printf("No of students having age in between 17 to 19 =%d",count);
getch();
}
30. Write a ‘C’ program to store a string and determine whether it is palindrome or not.
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char string[30];
int i,l,j;
clrscr();
printf("Enter a string:");
scanf("%s",string);
l=strlen(string);
for(i=0,j=l-1;i<l/2;i++,j--)
{
if(string[i]!=string[j])
{
printf("Not a Pallindrome");
getch();
exit(0);
}
}
printf("Pallindrome");
getch();
}
31. Write a ‘C’ program to find the sum of first ‘n’ natural numbers using recursive function.
#include <stdio.h>
#include <conio.h>
int add(int);
void main()
{
int n;
clrscr();
printf("Enter how many numbers:");
scanf("%d",&n);
printf("Sum of n natural numbers=%d",add(n));
getch();
}
int add(int n)
{
if(n==0)
return 0;
else
return(n+add(n-1));
}
32. Write a ‘C’ program to find the factorial of a number using recursive function.
#include <stdio.h>
#include <conio.h>
int factorial(int);
void main()
{
int n;
clrscr();
printf("Enter a numbers:");
C Solutions ,
12
scanf("%d",&n);
printf("Factorail=%d",factorial(n));
getch();
}
int factorial(int n)
{
if(n<=1)
return 1;
else
return(n*factorial(n-1));
}
33. A man is paid at the hourly rate of Rs.50/-per hour for the first 30 hours worked in a week.
There after the overtime is paid at 1.5 times the hourly rate for the next time 25 hours and 2
times the hourly rate for further hours worked. Input the number of hours worked in a week
and print weekly wages.
#include <stdio.h>
#include <conio.h>
void main()
{
int hr,w;
float tw;
w=50;
clrscr();
printf("Enter the hours worked:");
scanf("%d",&hr);
if(hr<=30)
tw=hr*w;
else if(hr<=55)
tw=(30*w)+((hr-30)*w*1.5);
else
tw=(30*w)+(25*w*2)+((hr-55)*w*2);
printf("Total Wages=Rs.%f",tw);
getch();
}
34. Write a program to store marks of ‘n’ students of a class in single dimensional array and find
highest, lowest and average mark of the class and also count the number of students who
obtained marks greater than 60.
#include <stdio.h>
#include <conio.h>
void main()
{
int marks[100],n,highest,lowest,sum=0,count=0,i;
float average;
clrscr();
printf("Enter how many students:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the marks:");
scanf("%d",&marks[i]);
}
highest=marks[0];
for(i=0;i<n;i++)
{
if(highest<marks[i])
highest=marks[i];
}
printf("\nHighest marks=%d",highest);
lowest=marks[0];
for(i=0;i<n;i++)
{
if(lowest>marks[i])
C Solutions ,
13
lowest=marks[i];
}
for(i=0;i<n;i++)
{
sum=sum+marks[i];
}
average=sum/n;
printf("\nAverage marks=%f",average);
printf("\nLowest marks=%d",lowest);
for(i=0;i<n;i++)
{
if(marks[i]>60)
count=count+1;
}
printf("\nNo. of Students getting marks more than 60=%d",count);
getch();
}
35. Write a program to generate Fibonacci series up to nth terms using recursive function.
#include <stdio.h>
#include <conio.h>
int fibonacci(int,int,int);
void main()
{
int n,a=0,b=1;
clrscr();
printf("Enter how many numbers:");
scanf("%d",&n);
fibonacci(a,b,n);
getch();
}
int fibonacci(int a,int b,int n)
{
int c;
if(n==0)
return 0;
else
{
c=a+b;
a=b;
b=c;
printf("\t%d",c);
fibonacci(a,b,n-1);
}
}
36. Write a program to stone ‘n’ numbers in an array and sort them in ascending order.
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,num[100],n,temp;
clrscr();
printf("Enter how many numbers:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the number:");
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(num[i]>num[j])
{
C Solutions ,
14
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
printf("THe sorted numbers in ascending order are\n");
for(i=0;i<n;i++)
{
printf("\n%d",num[i]);
}
getch();
}
37. Write a C program to calculate the factorial of given number ‘n’. The rules for calculating are
if n>0 calculate factorial, factorial=1, if n=0 and if n<0, display the error message.
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i,fact=1;
clrscr();
printf("Enter how many numbers:");
scanf("%d",&n);
if(n<0)
printf("ERROR-No factorail for n<0");
else if(n==0)
printf("Factorail=1");
else
{
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("Factorial=%d", fact);
}
getch();
}
38. National book center decides to prepare a Book Club. Members of the club are entitled to
special discounts on the purchase of the book. The discount of 15% is given to the members
if purchase amount exceeds 5000 and 10% is given it don’t exceed. Non members aren’t
normally given any discount. However if their purchase exceeds Rs. 5000, a discount of 7% is
given. Write a C program to analyze the above problem and find the net purchase amount.
#include <stdio.h>
#include <conio.h>
void main()
{
char ch;
int purchase;
float dis,pamount;
clrscr();
printf("Enter 'm' for members or 'n' for non members:");
scanf("%c",&ch);
printf("Enter the purchase amount:");
scanf("%d",&purchase);
switch(ch)
{
case 'm':
if(purchase>5000)
dis=(purchase*0.15);
else
dis=(purchase*0.10);
break;
case 'n':
C Solutions ,
15
if(purchase>5000)
dis=(purchase*0.07);
else
dis=0;
break;
default:
printf("Enter the valid choice either m or n:");
break;
}
pamount=purchase-dis;
printf("Net purhcase amount=%f",pamount);
getch();
}
39. Write a program to convert the line of lowercase text to uppercase text.
#include <stdio.h>
#include <conio.h>
void main()
{
char string[100];
clrscr();
printf("Enter a string:");
scanf("%s",string);
printf("String in uppercase=%s",strupr(string));
getch();
}
40. Write a program to print integers from 1 to 100 using WHILE loop
#include <stdio.h>
#include <conio.h>
void main()
{
int i;
clrscr();
i=1;
while(i<=100)
{
printf("%d\t",i);
i=i+1;
}
getch();
}
41. Write a program to calculate and print square of any given number.
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
clrscr();
printf("Enter a number:");
scanf("%d",&n);
printf("Square=%d",n*n);
getch();
}
42. Write a C program to display the sum of ‘n’ terms of even numbers.
#include <stdio.h>
#include <conio.h>
void main()
{
int i,n=0,num,sum=0;
clrscr();
printf("Enter the value of n");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
sum=sum+n;
C Solutions ,
16
n=n+2;
}
printf("Sum=%d",sum);
getch();
}
43. Write a C program to calculate the factorial of a given number using function.
#include <stdio.h>
#include <conio.h>
int factorial(int);
void main()
{
int n,fact;
clrscr();
printf("Enter any number");
scanf("%d",&n);
fact=factorial(n);
printf("factorial=%d",fact);
getch();
}
int factorial(int n)
{
int i,fact=1;
for(i=n;i>=1;i--)
{
fact=fact*i;
}
return fact;
}
44. Write a C program to print the first 10 terms of the following series using FOR loop. 1, 5, 9,
13, …….. (HSEB-2063)
#include <stdio.h>
#include <conio.h>
void main()
{
int i,n=1;
clrscr();
for(i=1;i<=10;i++)
{
printf("%d,",n);
n=n+4;
}
getch();
}
45. Write a C program to sort integer values in descending order. (HSEB-2063)
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,num[100],n,temp;
clrscr();
printf("Enter how many numbers:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the number:");
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(num[i]<num[j])
{
temp=num[i];
C Solutions ,
17
num[i]=num[j];
num[j]=temp;
}
}
}
printf("THe sorted integers in descending order are\n");
for(i=0;i<n;i++)
{
printf("\n%d",num[i]);
}
getch();
}
46. Write a C program to read the age of 40 students and count the number of students of the
age between 15 and 25. (HSEB-2063)
#include <stdio.h>
#include <conio.h>
void main()
{
int i,n,count=0,age[40];
clrscr();
for(i=0;i<40;i++)
{
printf("Enter the age of student");
scanf("%d",&age[i]);
}
for(i=0;i<40;i++)
{
if(age[i]>=15 && age[i]<=25)
count=count+1;
}
printf("No of students having age in between 15 and 25 =%d",count);
getch();
}
47. Write a C program to print the 10 positive integers and their factorials. (HSEB-2062)
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j;
long int fact;
clrscr();
printf("Number\tFactorial");
for(i=1;i<=10;i++)
{
printf("\n%d",i);
fact=1;
for(j=i;j>=1;j--)
{
fact=fact*j;
}
printf("\t%ld",fact);
}
getch();
}
48. Write a C program to input ‘n’ numbers and find out greatest and smallest number. (HSEB2062)
#include <stdio.h>
#include <conio.h>
void main()
{
int i,n,num[100],largest,smallest;
clrscr();
printf("Enter the value of n");
C Solutions ,
18
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter any number");
scanf("%d",&num[i]);
}
largest=num[0];
smallest=num[0];
for(i=0;i<n;i++)
{
if(largest<num[i])
largest=num[i];
if(smallest>num[i])
smallest=num[i];
}
printf("Largest number=%d",largest);
printf("\nSmallest number=%d",smallest);
getch();
}
49. Write a C program to read in a positive integer less than 20 and display its multiplication
table. (HSEB-2062)
#include <stdio.h>
#include <conio.h>
void main()
{
int i,num;
clrscr();
printf("Enter a positive integer less than 20");
scanf("%d",&num);
if(num<20)
{
for(i=1;i<=10;i++)
{
printf("\n%d*%d=%d",num,i,i*num);
}
}
else
printf("Enter the number less than 20 only");
getch();
}
50. Write a C program to input the names of ‘n’ numbers of students and sort them in
alphabetical order. (HSEB-2062)
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char name[30][25],temp[25];
int i,j,n;
clrscr();
printf("Enter how many students");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the name of the student:");
scanf("%s",name[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(name[i],name[j])>0)
{
strcpy(temp,name[i]);
C Solutions ,
19
strcpy(name[i],name[j]);
strcpy(name[j],temp);
}
}
}
printf("The sorted names are:");
for(i=0;i<n;i++)
{
printf("\n%s",name[i]);
}
getch();
}
51. Write a C program to read salaries of 200 employees and count the number of employees
getting salary between 5000 - 10000. (HSEB-2062)
#include <stdio.h>
#include <conio.h>
void main()
{
int sal[200],i,count=0;
clrscr();
for(i=0;i<200;i++)
{
printf("Enter the salary:");
scanf("%d",&sal[i]);
}
for(i=0;i<200;i++)
{
if(sal[i]>=5000 && sal[i]<=10000)
count=count+1;
}
printf("No of employees getting salary between 5000-10000=%d",count);
getch();
}
52. Write a C program that will read successive records from the data file and display each
record on the screen in an appropriate format. (HSEB-2062)
#include <stdio.h>
#include <conio.h>
void main()
{
char name[25];
char address[25];
char telno[25];
FILE *fp;
clrscr();
fp=fopen("record","r");
printf("Name\tAddress\tTelno\n");
while(fscanf(fp,"%s%s%s",name,address,telno)!=EOF)
{
printf("\n%s\t%s\t%s",name,address,telno);
}
fclose(fp);
getch();
}
53. Write a C program that reads different names and addresses into the computer and
rearrange the names into alphabetical order using the structure variable. (HSEB-2061)
54. Write a C program to display the multiplication table of series of given numbers entered by
the user. (HSEB-2061)
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i,j,num[100];
clrscr();
C Solutions ,
20
printf("Enter how many numbers of multiplication table to display:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the numbers:");
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
for(j=1;j<=10;j++)
{
printf("\n%d*%d=%d",num[i],j,num[i]*j);
}
}
getch();
}
55. Write a program using C language to read the age of 100 persons and count the number of
persons in the age group between 50 and 60. Use the ‘For’ and ‘Continue’ statements.
(HSEB-2061)
#include <stdio.h>
#include <conio.h>
void main()
{
int age[100],count=0,i;
clrscr();
for(i=0;i<100;i++)
{
printf("Enter the age of person");
scanf("%d",&age[i]);
}
for(i=0;i<100;i++)
{
if(age[i]>=50 && age[i]<=60)
count=count+1;
else
continue;
}
printf("No of persons in the age between 50 and 60=%d",count);
getch();
}
56. Write a C program to input a string and count the no of vowels in the string.
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char string[25];
int count=0,i,length;
clrscr();
printf("Enter the string:");
scanf("%s",string);
length=strlen(string);
for(i=0;i<length;i++)
{
if(string[i]=='a'||string[i]=='e'||string[i]=='i'||string[i]=='o'||string[i]=='u')
count=count+1;
}
printf("No of vowels=%d",count);
getch();
}
57. Write a C program to write the name, address and telno in a data file and read the
successive records to display them in the proper format.
#include <stdio.h>
C Solutions ,
21
#include <conio.h>
void main()
{
char name[25];
char address[25];
char telno[25];
FILE *fp;
clrscr();
fp=fopen("record","a");
printf("\nEnter the name:");
scanf("%s",name);
printf("\nEnter the address:");
scanf("%s",address);
printf("\nEnter the telno:");
scanf("%s",telno);
fprintf(fp,"\n%s\t%s\t%s",name,address,telno);
fclose(fp);
fp=fopen("record","r");
printf("Name\tAddress\t\t\tTelno\n");
while(fscanf(fp,"%s%s%s",name,address,telno)!=EOF)
{
printf("\n%s\t%s\t%s",name,address,telno);
}
fclose(fp);
getch();
}
58. Write a C program to write ‘n’ persons name, address and telno in a data file and display
them, reading the successive data from the file in proper format.
#include <stdio.h>
#include <conio.h>
void main()
{
char name[25];
char address[25];
char telno[25];
FILE *fp;
int i,n;
clrscr();
fp=fopen("rec.data","a");
printf("Enter how many records:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the name:");
scanf("%s",name);
printf("\nEnter the address:");
scanf("%s",address);
printf("\nEnter the telno:");
scanf("%s",telno);
fprintf(fp,"\n%s\t%s\t%s",name,address,telno);
}
fclose(fp);
fp=fopen("rec.data","r");
printf("Name\tAddress\t\t\tTelno\n");
while(fscanf(fp,"%s%s%s",name,address,telno)!=EOF)
{
printf("\n%s\t%s\t%s",name,address,telno);
}
fclose(fp);
getch();
}
59.
C Solutions ,
22
Download