computer programming (lab manual) pdf
computer programming (lab manual) pdf
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.
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.
------------------------------------------------------------------------------------------------------------------------
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:- #include<stdio.h>
int main (){
int a, b, sum;
printf (“Enter the value of a: “);
scanf (“%d”, &a);
sum = a + b;
Code:- #include<stdio.h>
int main (){
int s1, s2, s3, s4, s5, total = 500, sum;
sum = s1+s2+s3+s4+s5;
float per = (sum*100)/total;
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);
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;
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);
------------------------------------------------------------------------------------------------------------------------
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);
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);
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;
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;
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;
}
------------------------------------------------------------------------------------------------------------------------
Code:- #include<stdio.h>
int main () {
for(int i = 1; i <=10; i++){
printf (“%d\n”, i);
}
return 0;
}
------------------------------------------------------------------------------------------------------------------------
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);
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;
}
------------------------------------------------------------------------------------------------------------------------
Code:- #include<stdio.h>
int main (){
int n=1;
while (n<=10){
printf (“%d\n”, n);
n++;
}
return 0;
}
------------------------------------------------------------------------------------------------------------------------
Code:- #include<stdio.h>
int main () {
int n, sum=0;
printf (“Enter a number\n”);
scanf (“%d”, &n);