C Manual
C Manual
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 :
#include<stdio.h>
int main()
{
//printf()displays the string inside quotation
Printf(“Hello world!”);
Return0;
}
#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
#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);
}
#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
#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
#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
#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
#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
#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
#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
#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
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
#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
#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
#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
#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
#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
#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
#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
OUTPUT:
Enter the values:143 567
Swapped values are a=567 b=143
After function call a=143 b=567
OUTPUT:
Enter the values:
1432 567
Swapped values are *x=567 *y=1432
After function call a=567 b=1432
OUTPUT:
Enter a number:
4
The factorial of 24
#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
#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