Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

computer programming (lab manual) pdf

The document is a lab manual for computer programming, focusing on C++ and various programming concepts. It includes motivational quotes about programming, an introduction to different IDEs, and a series of programming exercises with code examples. The exercises cover basic programming tasks such as printing messages, performing arithmetic operations, and checking conditions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

computer programming (lab manual) pdf

The document is a lab manual for computer programming, focusing on C++ and various programming concepts. It includes motivational quotes about programming, an introduction to different IDEs, and a series of programming exercises with code examples. The exercises cover basic programming tasks such as printing messages, performing arithmetic operations, and checking conditions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1

Computer Programming(Lab Manual)

1. Motivational videos on programming.

Ans:- "Everybody in this country should learn how to program a computer because it teaches you
how to think".
-Steve Jobs

"you don't have to be genius to know how to code you need to be determined." As we all know
computers are everywhere if you want to work in agriculture, entertainment, building a house it just
all over, all things turned upside down by software. Now a days everything depends on computers.

"Our policy is literally to hire as many talented engineers as we can find".


-Mark Zuckerberg

To be able to actually come up with an idea and then see it in your hands and then be able to press a
button and have it be in millions of people's hands. I mean i think we're the first generation in the
world that's really ever had that kind of experience. The programmers of tomorrow are the wizards
of the future, you know we are gonna look like you have magic power compared to everybody else
its amazing i think its the closest thing we have to be a superpower.
------------------------------------------------------------------------------------------------------------------------

2. Introduction to C++/Code blocks/Visual stdio code.

Ans:- Turbo C++ :- Its a discontinued C++ compiler and integrated development envionment
originally from Borland. It was designed as a home and hobbyist counterpart for Borland C++. As
the developer focused more on professional programming tools later Turbo C++ product were made
as scaled down version of its professional compiler.
• Developer – Borland
• Initial release – May 1990
• Type – IDE

Code Blocks :- It is a free, open source cross platform IDE that supports multiple compiler
including GCC, clang, visual C++. It is developed in C++ using wx-widgets as the GUI toolkits,
using a plugin architecture, its capability and features are defined by the provided plugin.
• Developer – The code block team
• Initial release – 2005
• Type – IDE

Visual Studio code :- It is a source code editor made by Microsoft with the electron framework for
windows, linux and macos. Features including supports for debugging , syntax highlighting ,
intelligent code completion snippets, code refactoring and embedded git, users can change the
theme , keyboard shortcuts , preference and install extentions that add additional functionality.
• Developer – Microsoft
• Initial release – 2015
• Type – Source code editor
------------------------------------------------------------------------------------------------------------------------
3. Develop a program to print “Hello world”.

Code:- #include<stdio.h>
int main (){
printf (“Hello world\n”):
return 0;
}
------------------------------------------------------------------------------------------------------------------------

4. Develop a program to print your address (i) using single printf (ii) using multiple printf.

Code:- (i) using single printf


#include<stdio.h>
int main (){
printf (“Address:- Locality, City, Pin code, State, Country\n”);
return 0;
}

(ii) using multiple printf


#include<stdio.h>
int main (){
printf (“Address:- Locality\n”);
printf (“City\n”);
printf (“Pin code\n”);
printf (“State\n”);
printf (“Country\n”);
------------------------------------------------------------------------------------------------------------------------

5. Develop a program to print addition of 2 numbers (with scanf ).

Code:- #include<stdio.h>
int main (){
int a, b, sum;
printf (“Enter the value of a: “);
scanf (“%d”, &a);

printf (“Enter the value of b: “);


scanf (“%d”, &b);

sum = a + b;

printf (“Addition of %d and %d is %d\n”, a, b, sum);


return 0;
}
------------------------------------------------------------------------------------------------------------------------

6. Develop a program to convert temperature from Fahrenheit to celcius,


Hint: C = ((F-32)*5)/9.
Code:- #include<stdio.h>
int main (){
float temF, temC;
printf (“Enter the temperature in Fahrenheit\n”);
scanf (“%d”, &temF);

temC = ((temF – 32)*5)/9;

printf (“%d Fahrenheit is %d Celcius\n”, temF, temC);


return 0;
}
------------------------------------------------------------------------------------------------------------------------

7. Develop a program to find percentage of 5 subjects.

Code:- #include<stdio.h>
int main (){
int s1, s2, s3, s4, s5, total = 500, sum;

printf(“Enter the marks of subjects 1\n”);


scanf (“%d”, &s1);

printf(“Enter the marks of subjects 2\n”);


scanf (“%d”, &s2);

printf(“Enter the marks of subjects 3\n”);


scanf (“%d”, &s3);

printf(“Enter the marks of subjects 4\n”);


scanf (“%d”, &s4);

printf(“Enter the marks of subjects 5\n”);


scanf (“%d”, &s5);

sum = s1+s2+s3+s4+s5;
float per = (sum*100)/total;

printf(“Percentage of five subjects is %f\n”, per);


return 0;
}
------------------------------------------------------------------------------------------------------------------------

8. Develop a program to convert seconds into hours, minute & seconds print in HH:MM:SS
(Eg- 2:46:40).

Code:- #include<stdio.h>
int main (){
int sec, time, hour, min;
printf(“Enter seconds you want to convert\n”);
scanf (“%d”, &time);
hour = time/3600;
min = time/60;
sec = time % 60;
min = min % 60;
printf (“%d hours %d minute %d seconds\n”, hour, min, sec);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

9. Develop a program to check whether the given number is positive or negative.(using simple
if)

Code:- #include<stdio.h>
int main (){
int n;
printf (“Enter a number\n”);
scanf (“%d”, &n);

if(n>0){
printf (“Its a positive number\n”);
}
if(n<0){
printf (“Its a negative number\n”);
}
return 0;
}
------------------------------------------------------------------------------------------------------------------------

10. Develop a program to find out largest number from given three number using logical
operator (&&).

Code:- #include<stdio.h>
int main(){
int num1, num2, num3;

printf (“Enter the value of 1st , 2nd and 3rd number respectively\n”);
scanf (“%d %d %d”, &num1, &num2, &num3);

if (num1>num2 && num1>num3){


printf (“1st number is largest\n”);
}
else if (num2>num1 && num2>num3){
printf (“2nd number is largest\n”);
}
else
printf (“3rd number is largest\n”);
return 0;
}
------------------------------------------------------------------------------------------------------------------------
11. Develop a program to check whether the given number is positive or negative.(using
if...else...)

Code:- #include<stdio.h>
int main () {
int n;
printf (“Enter a number\n”);
scanf (“%d”, &n);

if (n>0){
printf (“Positive number\n”);
}
else if (n==0){
printf (“Your input is zero\n”);
}
else
printf (“Negative number\n”);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

12. Develop a program to find out largest number from given three numbers without using
logical operator(&&). (using nested if)

Code:- #include<stdio.h>
int main (){
int n1, n2, n3;

printf ("Enter your 1st number\n");


scanf ("%d", &n1);
printf ("Enter your 2nd number\n");
scanf ("%d", &n2);
printf ("Enter your 3rd number\n");
scanf ("%d", &n3);

if (n1>n2){
if (n1>n3){
printf ("Number 1st is greatest which is %d\n", n1);
}
}
else if (n2>n1)
{
if (n2>n3)
{
printf ("Number 2nd is greatest which is %d\n", n2);
}
}
else
printf ("Number 3rd is greatest which is %d\n", n3);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

13. Develop a program to check whether the given number is leap year or not. (If a year can
be divisible by 4 but not divisible by 100 then it is leap year but if it is divisible by 400 then it
is leap year). (Using if...else if... else...)

Code:- #include<stdio.h>
int main () {
int n;
printf (“Enter a year: “);
scanf (“%d”, &n);

if(n%4==0 && n%100 !=0){


printf (“Its a leap year\n”);
}
else if (n%400 == 0){
printf (“Its a leap year\n”);
}
else
printf (“Its not a leap year\n”);
return 0;
}

------------------------------------------------------------------------------------------------------------------------

14. Develop a program to perform addition, subtraction, multiplication and division of 2


numbers as per user's choice.

Code:- #include<stdio.h>
int main () {
int n1, n2, ch;
printf (“Enter your 1st number: “);
scanf (“%d”, &n1);
printf (“Enter your 2nd number: “);
scanf (“%d”, &n2);

printf (“Enter what operation you want to perform\n”);


printf (“1 for Addition, 2 for Subtraction, 3 for Multiplication and 4 for Division\n”);

scanf (“%d”, &ch);


switch (ch){
case 1:
printf (“%d + %d = %d\n”, n1, n2, n1+n2);
break;
case 2:
printf (“%d - %d = %d\n”, n1, n2, n1-n2);
break;
case 3:
printf (“%d * %d = %d\n”, n1, n2, n1*n2);
break;
case 4:
if(n2>0){
printf (“%d / %d = %d\n”, n1, n2, n1/n2);
break;
default:
printf (“You entered an invalid input\n”);
break;
}
return 0;
}
------------------------------------------------------------------------------------------------------------------------

15. Three sides of triangle are entered through the keyboard develop a program to check
whether the triangle is isoscles, equilateral, scalene or right angled triangle.

Code:- #include<stdio.h>
int main () {
int s1, s2, s3;
printf (“Enter 1st side: “);
scanf (“%d”, &s1);
printf (“Enter 2nd side: “);
scanf (“%d”, &s2);
printf (“Enter 3rd side: “);
scanf (“%d”, &s3);

if(s1 == s2 && s2 == s3){


printf (“This is equilateral triangle\n”);
}
else if (s1 == 90 || s2 == 90 || s3 == 90){
printf (“This is right angled triangle\n”);
}
else if (s1 == s2 || s2 == s3 || s3 == s1){
printf (“This is isoscles triangle\n”);
}
else if (s1 != s2 && s2 != s3 && s3 != s1){
printf (“This is scalena triangle\n”);
}
else
printf (“This is other types of triangle\n”);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

16. Develop a program to find out largest number from given 2 numbers. (using exp? exp2:
exp3 )

Code:- #include<stdio.h>
int main (){
int n1, n2, lar;

printf (“Enter your 1st number: “);


scanf (“%d”, &n1);
printf (“Enter your 2nd number: “);
scanf (“%d”, &n2);
lar = n1;
(lar < n2 ? Lar = n2 : lar);
printf (“%d is largest\n”, lar);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

17. Develop a program to read 3 number, multiply largest number from first two numbers to
third one.

Code:- #include<stdio.h>
int main () {
int n1, n2, n3, lar;
printf (“Enter your 1st number: “);
scanf (“%d”, &n1);
printf (“Enter your 2nd number: “);
scanf (“%d”, &n2);
printf (“Enter your 3rd number: “);
scanf (“%d”, &n3);

lar = n1;
(lar < n2 ? lar = n2 : lar);
(lar < n3 ? lar = n3 : lar);
printf (“%d is largest\n”, lar);
n1 = n1*lar;
n2 = n2*lar;
n3 = n3*lar;

printf (“After multiplying the largest number to all\n”);


printf (“1st number = %d\n 2nd number = %d\n 3rd number = %d\n”, n1, n2, n3);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

18. Develop a program to print day name based on day number.

Code:- #include<stdio.h>
int main (){
int n;
printf (“Enter day number: “);
scanf (“%d”, &n);

switch (n){
case 1:
printf (“Monday\n”);
break;
case 2:
printf (“Tuesday\n”);
break;
case 3:
printf (“Wednesday\n”);
break;
case 4:
printf (“Thursday\n”);
break;
case 5:
printf (“Friday\n”);
break;
case 6:
printf (“Saturday\n”);
break;
case 7:
printf (“Sunday\n”);
break;
default:
printf (“Your input is invalid\n”);
break;
}
return 0;
}
------------------------------------------------------------------------------------------------------------------------

19. Develop a program to print 1 to 10.

Code:- #include<stdio.h>
int main () {
for(int i = 1; i <=10; i++){
printf (“%d\n”, i);
}
return 0;
}
------------------------------------------------------------------------------------------------------------------------

20. Develop a program to find factorial of the given number.

Code:- #include<stdio.h>
int main () {
int n, a, b, count, temp;
printf (“Enter a number to find factorial of: “);
scanf (“%d”, &n);

count =2;
a =0;
b =1;
while(count <=n){
temp = b;
b = a+b;
a = temp;
count++;
}
printf (“%d\n”, b);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

21. Develop a program to find whether the given number is prime or not using break.

Code:- #include<stdio.h>
int main (){
int n, i, count =0;
printf (“enter a number\n”);
scanf (“%d”, &n);

for (i = 2; i<n/2; i++){


if(n%i==0){
count++;
}
}
if(count == 0){
printf (“prime number\n”);
}
else
printf (“Not a prime number\n”);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

22. Develop a program to print digits of given number.

Code:- #include<stdio.h>
int main () {
int n, count = 0;
printf (“Enter a number\n”);
scanf (“%d”, &n);

while(n!=0){
++count;
n=n/10;
}
printf (“%d\n”, count);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

23. Develop a program to check whether the given number is palindrome or not.

Code:- #include<stdio.h>
int main () {
int n, ans = 0, rem;
printf (“Enter a number\n”);
scanf (“%d”, &n);
int temp = n;
while (n>0){
rem = n%10;
n = n/10;
ans = ans*10+rem;
}
if(temp ==ans){
printf (“palindrome number\n”);
}
else
printf (“Not palindrome\n”);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

24. Develop a program to check whether the given number is Armstrong or not.

Code:- #include<stdio.h>
int main (){
int n, rem, sum =0, temp;
printf (“Enter a number\n”);
scanf (“%d”, &n);
temp = n;
while(n != 0){
rem = n%10;
sum = sum +rem*rem*rem:
n= n/10;
}
if(temp == sum){
printf (“Armstrong\n”);
}
else
printf (“Not armstrong\n”);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

25. Develop a program to print number from 1 to 10.(using while loop)

Code:- #include<stdio.h>
int main (){
int n=1;
while (n<=10){
printf (“%d\n”, n);
n++;
}
return 0;
}
------------------------------------------------------------------------------------------------------------------------

26. Develop a program to print odd number from 1 to n.


Code:- #include<stdio.h>
int main () {
int n;
printf (“Enter a number\n”);
scanf (“%d”, &n);

for (int i = 1; i<=10; i++){


if(i%2==0){
printf (“%d\n”, i);
}
}
return 0;
}
------------------------------------------------------------------------------------------------------------------------

27. Develop a program to calculate the sum of first n natural number.

Code:- #include<stdio.h>
int main () {
int n, sum=0;
printf (“Enter a number\n”);
scanf (“%d”, &n);

for(int i = 1; i<=n; i++){


sum = sum+i;
}
printf (“%d\n”, sum);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

This is the end for Mid Sem 1

You might also like