11 C Assignments

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

1. Program 1: To display a message.

#include <iostream.h> void main() { cout << "Hello World!" << endl; } #include <iostream.h> void main() { int a,b; a=5; b=a*a; cout << "The square is " << b; } Header File The main Function (starting and ending point of a C++ program) Body of the function

2. Program 2: To calculate the square of a number

3. Program 3: To add two numbers


#include <iostream.h> void main() { int a,b,c; cout <<Enter first number; cin >>a; cout <<Enter second number; cin >>b; c=a+b; cout << "The sum is " << c; }

4. Program 4: To calculate simple interest


#include <iostream.h> void main() { int p,r,t,i; cout <<Enter Principal; cin >>p; cout <<Enter Rate; cin >>r; cout <<Enter Time; cin >>t; i = p*r*t/100; cout << "The interest is " << i; } 5. Write a program in C++ to accept radius of a circle as input and display its area and circumference. #include<iostream.h> void main() { const float pi=3.14; float radius, area, circumference; cout<< Enter the radius=; cin>>radius; area=pi*radius* radius; circumference=2*pi* radius; cout<< The area of the circle is =<<area<<\n; cout<< The circumference of the circle is =<<circumference<<\n; } 6. Write a program in C++ to accept three numbers as input and display their sum, product and average. #include<iostream.h> void main() { int n1, n2, n3, sum, product; float average; cout<< Enter the three numbers =; cin>>n1>>n2>>n3; sum= n1+n2+n3; product= n1*n2*n3; average= float(sum)/3; cout<< The sum of three numbers is =<< sum<<\n; cout<< The product of three numbers is =<<product<<\n; cout<< The average of three numbers is =<<average<<\n; } 7. 8. 9. 10. Write a C++ program to input length and breadth of a rectangle and display the area and perimeter. Write a program to input marks of five subjects and calculate the total and percentage. Write a program to input three sides of a triangle and calculate the area. Write a program to input principal, rate and time and calculate the compound interest.

11. Display the following output on the screen using a single cout statement: C++ A III generation programming language Uses Object Oriented Programming 12. Write a C++ program to input the cost price and selling price of a product and calculate the profit or loss.

13. Write a C++ program to input a number and display the square and cube of that number. 14. Write a C++ program to input temperature in Fahrenheit and convert in to centigrade. c = (5.0/9)*(f-32) 15. Write a prog. to input marks of a student out of 100 & check whether the student is pass or fail. #include<iostream.h> #include<conio.h> void main( ) { int m; cout<<enter the marks; cin>>m; if(m>=33) cout<<Pass; else cout<<Fail; getch(); } 16. Write a prog to input age of a person and check whether the person is eligible to vote or not. 17. Write a prog to input a number and check whether the number is positive or negative. 18. Write a prog to input a number and check whether the number is even or odd. 19. Write a prog to input two numbers and find the greater of the two numbers. 20. Write a program to input a number, if the number is odd print its square and if the number is even print its cube. 21. Write a program to input a number and check whether it is divisible by 5 or not. 22. Write a program to input the monthly salary and calculate the income tax on the following basis. Annual Salary Income Tax >150000 30% 100000 to 150000 20% 50000 to 99999 10% else Nil 23. Write a program to input the marks of 3 subjects and calculate the total and percentage Also the program should display the grade on the following basis. Marks Grade 85 to 100 A 70 to 84 B 55 to 69 C 40 to 54 D less than 40 E 24. Write a program to input the sales and calculate the commission on the following basis. Sales Comm >15000 15% 10000 to 15000 12% 5000 to 9999 10% else 3% (Use switch to do the following programs) 25. Write a program to input a character from the user and check whether it is a vowel or a consonant. 26. Write a program to input a month number (1-12) and display the month name and the number of days in the given month. For example if the month number is 5, The output should be May has 31 days

1. Write a program to input an array of 10 integers and find the sum and average of these numbers. 2. Write a program to input an array of 10 integers and find the minimum value. 3. Write a program to input an array of 10 integers and change it. At all even positions add 5 to the value and at all odd positions multiply by 2. 4. Write a program to input an array of 10 integers and perform linear search.

1. Write a program to input an array of 10 integers and find the sum and average of these numbers. 2. Write a program to input an array of 10 integers and find the minimum value. 3. Write a program to input an array of 10 integers and change it. At all even positions add 5 to the value and at all odd positions multiply by 2. 4. Write a program to input an array of 10 integers and perform linear search.

1. Write a program to input an array of 10 integers and find the sum and average of these numbers. 2. Write a program to input an array of 10 integers and find the minimum value. 3. Write a program to input an array of 10 integers and change it. At all even positions add 5 to the value and at all odd positions multiply by 2. 4. Write a program to input an array of 10 integers and perform linear search.

1. Write a program to input an array of 10 integers and find the sum and average of these numbers. 2. Write a program to input an array of 10 integers and find the minimum value. 3. Write a program to input an array of 10 integers and change it. At all even positions add 5 to the value and at all odd positions multiply by 2. 4. Write a program to input an array of 10 integers and perform linear search.

1. Write a program to input an array of 10 integers and find the sum and average of these numbers. 2. Write a program to input an array of 10 integers and find the minimum value. 3. Write a program to input an array of 10 integers and change it. At all even positions add 5 to the value and at all odd positions multiply by 2. 4. Write a program to input an array of 10 integers and perform linear search.

1. Write a program to input an array of 10 integers and find the sum and average of these numbers. 2. Write a program to input an array of 10 integers and find the minimum value. 3. Write a program to input an array of 10 integers and change it. At all even positions add 5 to the value and at all odd positions multiply by 2. 4. Write a program to input an array of 10 integers and perform linear search.

1. Write a program to input an array of 10 integers and find the sum and average of these numbers. 2. Write a program to input an array of 10 integers and find the minimum value. 3. Write a program to input an array of 10 integers and change it. At all even positions add 5 to the value and at all odd positions multiply by 2. 4. Write a program to input an array of 10 integers and perform linear search.

1. Write a program to input an array of 10 integers and find the sum and average of these numbers. 2. Write a program to input an array of 10 integers and find the minimum value. 3. Write a program to input an array of 10 integers and change it. At all even positions add 5 to the value and at all odd positions multiply by 2. 4. Write a program to input an array of 10 integers and perform linear search. 3

You might also like