0% found this document useful (0 votes)
100 views24 pages

C Manual

The document is a certificate from Loyola Academy Degree & PG College in Secunderabad certifying that the attached document is a bonafide record of work done in the 'Problem Solving and Programming Through C' lab during the 1st semester of the 1st year in the academic year 2023-2024. It contains the student's name, class, and hall ticket number along with signatures of the internal examiner, principal, and external examiner. The attached record contains programs written in C language with problem numbers and descriptions.

Uploaded by

shekapurampranay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views24 pages

C Manual

The document is a certificate from Loyola Academy Degree & PG College in Secunderabad certifying that the attached document is a bonafide record of work done in the 'Problem Solving and Programming Through C' lab during the 1st semester of the 1st year in the academic year 2023-2024. It contains the student's name, class, and hall ticket number along with signatures of the internal examiner, principal, and external examiner. The attached record contains programs written in C language with problem numbers and descriptions.

Uploaded by

shekapurampranay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Loyola Academy Degree & PG College

Old Alwal,Secunderabad – 500010


[AN AUTONOMOUS DEGREE COLLEGE AFFILIATED TO OSMANIA UNIVERSITY]
‘A college with potential for excellence’ by UGC. Re-accredited with
GRADE ‘A’ by NAAC

Department Of Computer Science & information


technology
Practical Record : Problem Solving And Programming Through ‘C’

Certificate
This is to Certify that this is a BONAFIDE RECORD of the work
done in PROBLEM SOLVING AND PROGRAMMING
THROUGH ‘C’ lab during the 1st YEAR / 1st SEMESTER in the
academic year 2023-2024.

Name :
Class :
Hall Ticket Number :

Internal Examiner Principal External Examiner


INDEX
S PROGRAM PAGE
NO NUMBERS
1 Program to Hello world
2 Program to Hello world at 5 times using for loop
3 Program to find the multiplication of integer
4 Program to find the addition of integer
5 Program to find if the given number is even or odd
6 Program to swapping two numbers
7 Program of Arthemetic
8 Program to perform arithmetic operations using switch case

9 Program to calculate sum of 10 natural numbers


10 Program to print multiplication table of a number
11 Program to find the grade of a student
12 Program to find factorial of a given number
13 Program to find sum of the digits of a given number
14 Program to find reverse of a number
15 Program to check If the given number is a palindrome or not

16 Program to check whether a number is Armstrong or not


17 Program to print the Fibonacci series using do_ _ _ while
18 Program to print the factors of a given number
19 Program to print a number triangle
20 Program to print Multiplication table matrix using nested for
loop
21 Program to accept and display 1-Dimensional array
22 Program to display the elements of an array in reverse order

23 Program to find the sum of the elements of the array


24 Program to find the smallest of the elements of the array
25 Program to find the greatest of the elements of the array
26 Program to find the length of the strings /numbers of
characters
27 Program to copy one string to another string
28 Program to add 2 numbers using functions
29 Program to swap the values of two variables using call by
value
30 Program to swap the values of two variables using call by
reference
31 Program to find the factorial of a number using Recursion

32 Program to find the greatest of 3 numbers using nested if


33 Program to check if the number is positive or negative

1./*Program to Hello world*/

#include<stdio.h>
int main()
{
//printf()displays the string inside quotation
Printf(“Hello world!”);
Return0;
}

Out put: Hello world !

2. /*Program to print Hello world at 5 times using for loop*/

#include <stdio.h>
#include <conio.h>
void main()
{
int i= 1:
while (i<6)
{
printf (''hello world ''):
printf (''\n""):
i++

}
return o;
out put : Hello world
Hello world
Hello world
Hello world
Hello world
3. /*Program to find multiplication of integer*/

#include<stdio.h>
Int main()
{
int number1,number2,product;
prpintf(“Enter two integers”);
scanf("%d, %d”,&number1,number2);
product=number1+number2;
printf(“%d*%d”,number1,number2,product);
}

OUTPUT :
Enter the integer : 5*4
20

4. /*Program to find the addition of two numbers*/

#include<stdio.h>
Int main()
}
Int number1,number2,sum;
Printf(“Enter two integer”);
Scanf(“%d, %d”,&number1,number2);
Sum=number1+number2;
Printf (“%d+%d”,number1,number2,sum);
}

OUTPUT : Enter the values of 2+3 = 5

5. /*Program to find if the given number is even or odd*/

#include<stdio.h>
#include<conio.h>
void main()
{
intx,r;
clrscr();
printf("Enter the value of x:");
scanf("%d",&x);
r=x%2;
if(r==0)
printf("\n %d is even",x);
else
printf("\n %d is odd",x);
}
OUTPUT:
Enter the value of x:365
365 is odd

6. /*Program to swapping two numbers */

#include<stdio.h>
Int main()
Int first, second,temp;
printf("Enter the first value");
Scanf("%d", & first);
Printf("Enter the second value").
Scanf("%d", & second);
temp = first,
first =second;
second= temp;
printf("After swapping first value is " & first. );
Printf ("After swapping second value is”, second);
}
Output :
Enter the first value
Enter the second value.
After swapping-first value 12
After swapping second value 15

7. /*Program to Arthemetic*/

#include<stdio.h>
Int main()
{
Int a=4, b=2
Printf(“addition”, a+b);
Printf(“substraction”, a-b);
Printf(“multiplication”, a*b);
Printf(“division”, a/b);
Printf(“modular division”, a%b);
OUTPUT:
a+b=6
a-b= 2
a*b= 8
a/b= 2
a%b= 0

8. /*Program to perform arithmetic operators using switch case*/

#include<stdio.h>
#include<conio.h>
void main()
{
intch;
inta,b,result;
clrscr();
printf("Enter any two numbers");
scanf("%d%d",&a,&b);
printf("\n ***operations***");
printf("\n 1.(+)addition");
printf("\n 2.(-)subtraction ");
printf("\n 3.(*)multiplication");
printf("\n 4.(/)division");
printf("\n Enter the operation");
scanf("%d",&ch);
switch(ch)
{
case1:
result=a+b;
printf("\n The calculated result is : %d",result);
break;
case2:
result=a-b;
printf("\n The calculated result is : %d",result);
break;
case3:
result=a*b;
printf("\n The calculated result is : %d",result);
break;
case4:
result=a/b;
printf("\n The calculated result is : %d",result);
break;
default:
printf("\n Wrong choice");
}
}

OUTPUT:
Enter any two numbers 2 3
***operations***
1.(+)addition
2.(-)subtraction
3.(*)multiplication
4.(/)division
Enter the operation 2
The calculated result is : -1

9. /* Program to print the sum of ‘n’ natural numbers*/

#include<stdio.h>
#include<conio.h>
void main()
{
inti,n,s=0;
clrscr();
printf("Enter a value for n:");
scanf("%d",&n);
i=1;
while(i<=n)
{
s=s+i;
i=i+1;
}
printf("\n Sum=%d",s);
}

OUTPUT:
Enter a value for n:9
Sum=45
10. /*Program to print the multiplication table of a given number*/

#include<stdio.h>
#include<conio.h>
void main()
{
inti,n,p;
printf("Enter a value for n:");
scanf("%d",&n);
i=1;
while(i<=10)
{
p=n*i;
printf("\n %d*%d=%d",n,i,p);
i=i+1;
}
}

OUTPUT:
Enter a value for n:50
5*1=5
5*2=10
5*3=15
5*4=20
5*5=25
5*6=30
5*7=35
5*8=40
5*9=45
5*10=50

11. /*Program to find the grade of a student*/

#include<stdio.h>
#include<conio.h>
void main()
{
int m1,m2,m3,total;
floatavg;
clrscr();
printf("Enter the marks");
scanf("%d%d%d",&m1,&m2,&m3);
total=m1+m2+m3;
avg=total/3;
if(avg<=100 &&avg>=60)
printf("\n Division 1");
else if (avg<=60 &&avg>=50)
printf("\n Division 2") ;
else if (avg<=50 &&avg>=40)
printf("\n Division 3");
else
printf("\n Fail");
}

OUTPUT:
Enter the marks 44 72 86
Division 1

12. /*Program to find factorial of a given number*/

#include<stdio.h>
#include<conio.h>
void main()
{
inti,n,f=i;
clrscr();
printf("enter a value for n:");
scanf("%d",&n);
i=1;
while(i<=n)
{
f=f*i;
i=i+1;
}
printf("\n factorial=%d",f);
}

OUTPUT:
enter a value for n:4
factorial=24

13. /* Program to find sum of digits of a given number*/

#include<stdio.h>
#include<conio.h>
void main()
{
intn,r,s=0;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf("\n Sum=%d",s);
}

OUTPUT:
Enter the value of n: 924
Sum=15

14. /*Program to find the reverse of a given number*/

#include<stdio.h>
#include<conio.h>
void main()
{
intn,r,s=0;
clrscr();
printf("\n Enter a number:");
scanf("%d",&n);
while(n>0)
{
r=n%10;
s=(s*10)+r;
n=n/10;
}
printf("\n Reverse=%d",s);
}

OUTPUT:
Enter a number:1431
Reverse=1341

15. /*Program to check if a given number is a palindrome*/


#include<stdio.h>
#include<conio.h>
void main()
{
intn,r,s=0,n1;
clrscr();
printf("Enter a number:");
scanf("%d",&n);
n1=n;
while( n>0)
{
r=n%10;
s=(s*10)+r;
n=n/10;
}
if(s==n1)
printf("\n The given number is a palindrome");
else
printf("\n The given number is not a palindrome");
}

OUTPUT 1:
Enter a number:141
The given number is a palindrome
OUTPUT 2:
Enter a number:123
The given number is not a palindrome

16. /*Program to check if the given number is an Armstrong


number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n1,r,n,s=0;
clrscr();
printf("Enter the number");
scanf("%d",&n);
n1=n;
while(n>0)
{
r=n%10;
n=n/10;
s=s+(r*r*r);
}
if(s==n1)
printf("\n The given number is an Armstrong number");
else
printf("\n The given number is not an Armstrong number");
getch();
}

OUTPUT:
Enter the number 153
The given number is an Armstrong number

17. /*Program to find the Fibonacci series*/

#include<stdio.h>
#include<conio.h>
void main()
{
int f1=0,f2=0,f3,n;
clrscr();
printf("Enter the limit:");
scanf("%d",&n);
printf("\n Fibonacci series:");
printf("\n %d",f1);
printf("\n %d",f2);
do
{
f3=f1+f2;
printf("%d",f3);
f1=f2;
f2=f3;
}
while(f3<=n);
}
OUTPUT:
Enter the limit:6
Fibonacci series is
0
1
1
2
3
5

18. /*Program to print factors of a given number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a, i;
clrscr();
printf(“Enter a number:”);
scanf(“%d”,&a);
for(i=1;i<=10;i++)
{
if(a%i==0)
printf(“\n%d”,i);
}
getch()
}

Output:

Enter a number: 6
1
2
3
6
19. /*Program to print number triangle 1
12
123
1 2 3 4*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
intr,c;
clrscr();
for(r=1;r<=4;r++)
{
for(c=1;c<=r;c++)
{
printf("%d",r);
}
printf("\n");
}
getch();
}

OUTPUT:
1
12
123
1234

20. /*Program to print multiplication table matrix using nested for


loop*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,p,j;
for i=1;i<=10;i++)
{
for(j=1;j<=10;j++)
{
p=i*j;
printf(“%d\t”,p);
}
printf(“\n”);
}

Output:
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100

21. /*Program to accept and display array element*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i;
clrscr();
printf("Enter the array elements:");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
printf("\n Array elements are:");
for(i=0;i<5;i++)
printf("\n %d",a[i]);
getch();
}

OUTPUT:
Enter the array elements:56 87 39 73 23
Array elements are:
56
87
39
73
23
22. /*Program to print array elements in the reverse order*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,l;
clrscr();
printf("Enter the array elements:");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
printf("\n The array elements are:");
for(i=4;i>=0;i--)
printf("\n %d",a[i]);
getch();
}

OUTPUT:
Enter the array elements:43 64 76 97 21
The array elements are:
21
97
76
64
43

23. /*Program to find the sum of the elements in the array*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,s=0;
clrscr();
printf(“Enter the array elements:");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
s=s+a[i];
}
printf("\n The sum of elements=%d",s);
getch();
}

OUTPUT:
Enter the array elements:1 5 3 2 6
The sum of elements=17

24. /*Program to find the lowest value from the given array
elements*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,l;
clrscr():
printf("Enter the array elements:");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
l=a[0];
for(i=1;i<5;i++)
{
if (a[i]<1)
l=a[i];
}
printf("The lowest value is:%d",l);
getch();
}

OUTPUT:
Enter the array elements:2 35 76 84 45
The lowest value is:2

25. /*Program to find the greatest value from the given array
elements*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,l;
clrscr():
printf("Enter the array elements:");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
l=a[0];
for(i=1;i<5;i++)
{
if (a[i]>1)
l=a[i];
}
printf("The greatest value is:%d",l);
getch();
}

OUTPUT:
Enter the array elements:2 35 76 84 45
The lowest value is:84

26. /*Program to find the length of a string*/

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s[10];
int i,l=0;
clrscr();
printf("\n Enter a string :");
gets(s);
for(i=0,l=0;s[i]!='\0';i++)
l++;
printf("\n Length of string is %d",l);
getch();
}

OUTPUT:
Enter a string :Loyola academy
Length of string is 14
27./*Program to copy one string to another string*/

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s[10],t[10];
int i;
clrscr();
printf("Enter a string:");
gets(s);
for(i=0;s[i]!='\0';i++)
t[i]=s[i];
t[i]='\0';
printf("\n orginal string is %s",s);
printf("\n copied string is %s",t);
getch();
}

OUTPUT:
Enter a string:c program
orginal string is c program
copied string is c program

28./*Program to find sum of two numbers using functions*/


#include<stdio.h>
#include<conio.h>
#include<string.h>
void (int,int);
void main()
{
int x,y;
clrscr();
printf("Enter two numbers:");
scanf("%d%d",&x,&y);
sum (x,y);
getch();
}
void sum(int a,int b)
{
int s;
s=a+b;
printf("\n sum=%d",s);
}
OUTPUT:
Enter two numbers:2,2
sum=4

29./*Program to illustrate call-by-value*/


#include<stdio.h>
#include<conio.h>
void swap(int,int);
void main()
{
int a,b;
clrscr();
printf("Enter the values:");
scanf("%d%d",&a,&b);
swap(a,b);
printf("\n After function call a=%d b=%d",a,b);
getch();
}
void swap(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
printf("\n Swapped values are a=%d b=%d",a,b);
}

OUTPUT:
Enter the values:143 567
Swapped values are a=567 b=143
After function call a=143 b=567

30./*Program to illustrate call-by-reference*/


#include<stdio.h>
#include<conio.h>
void swap(int *,int *);
void main()
{
int a,b;
clrscr();
printf("Enter the values:");
scanf("%d%d",&a,&b);
swap(&a,&b);
printf("\n After function call a=%d b=%d",a,b);
getch();
}
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
printf("\n Swapped values are *x=%d *y=%d",*x,*y);
}

OUTPUT:
Enter the values:
1432 567
Swapped values are *x=567 *y=1432
After function call a=567 b=1432

31. /*Program to find factorial using recursion*/


#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,f;
clrscr();
printf("Enter a number: \n");
scanf("%d",&n);
f=fact(n);
printf("The factorial of %d",f);
getch();
}
int fact(int n)
{
if((n==0) || (n==1))
return (1);
else
return (n*fact(n-1));
}

OUTPUT:
Enter a number:
4
The factorial of 24

32. /*Program to find greatest of three numbers*/

#include<stdio.h>
#include<conio.h>
void main()
{
inta,b,c;
clrscr();
printf("Enter any three numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
printf("\n %d is greater of three numbers",a);
if(b>a && b>c)
printf("\n %d is greater of three numbers",b);
else
printf("\n %d is greater of three numbers",c);
getch();
}

OUTPUT:
Enter any three numbers:5 8 32
32 is greater of three numbers

33. /*Program to find if the given number is positive or negative*/

#include<stdio.h>
#include<conio.h>
void main()
{
int x;
clrscr();
printf("Enter the value of x:");
scanf("%d",&x);
if(x>0)
printf("\n %d is positive",x);
else
printf("\n %d is negative",x);
}

OUTPUT 1:
Enter the value of x:123
123 is positive

OUTPUT 2:
Enter the value of x:-143
-143 is negative

You might also like