Professional Documents
Culture Documents
Solution :
2
Solution :
3
Solution :
4
Solution :
5
Solution :
6
Solution :
7
Solution :
8
Solution :
9
Solution :
10
Solution :
11
Solution :
12
Solution :
13
Soultion :
14
15
16
17
18
19
20
21
22
23
24
25 1)
Solution :
2)
Solution :
3)
Solution :
4)
Solution :
5)
Solution :
6)
Solution :
26
Solution :
27
Solution :
28
Solution :
29
Solution :
30
Solution :
31
Solution :
32
Solution :
33
Solution :
34
Solution :
35
Solution :
36
Solution :
37
Solution :
38
Solution :
39
Solution :
40
Solution :
41
Solution :
42
Solution :
43
Solution :
44
Solution :
45
Solution :
46
Solution :
47
Solution :
48
Solution :
49
Solution :
50
Solution :
51
Solution :
KADI SARVA VISHWAVIDYALA
LDRP-ITR GANDHINAGAR
CE/IT DEPARTMENT
FUNDAMENTAL OF PROGRAMMING (CC 103 N) LAB MANUAL
PRACTICAL SET : 1
Write a program to print your address.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\n\nMY JOB ADDRESS IS");
printf("\n------------------------------------------------");
printf("\n\nL.D.R.P.-ITR,\nMCA Department,\nGandhinagar.");
printf("\n------------------------------------------------");
getch();
}
Write a program to perform all the arithmetic operations together in a single program.
#include<stdio.h>
#include<conio.h>
void main()
{
float no1,no2,sum,mul,sub,div;
clrscr();
printf("\nENTER THE NO1:====>");
scanf("%f",&no1);
printf("\nENTER THE NO2:====>");
scanf("%f",&no2);
sum=no1+no2;
mul=no1*no2;
sub=no1-no2;
div=no1/no2;
printf("\n\nADDITION OF TWO NUMBERS:===>%f",sum);
printf("\n\nSUBTRACTION OF TWO NUMBERS:===>%f",sub);
printf("\n\nMULTIPLICATION OF TWO NUMBERS:===>%f",mul);
printf("\n\nDIVISION OF TWO NUMBERS:===>%f",div);
getch();
}
PRACTICAL SET 2
Write a program to print a character entered by user.
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(""\n\nEnter the Character:==>"");
scanf(""%c"",&ch);
printf("Entered Character Is:==>%c",ch);
getch();
}
Write a program to swap the values of two variables using third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("ENTER THE VALUE OF A & B:===>");
scanf("%d %d",&a,&b);
temp=a;
a=b;
b=temp;
printf("\t\t\n\n USING THIRD VARIABLE");
printf("\t\t\nVALUE OF A IS:===>%d",a);
printf("\t\t\nVALUE OF B IS:===>%d",b);
getch();
}
Write a program to swap the values of two variables without using third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("ENTER THE VALUE OF A & B:===>");
scanf("%d %d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("\t\n\n WITHOUT THIRD VARIABLE");
printf("\t\t\nVALUE OF A IS:===>%d",a);
printf("\t\t\nVALUE OF B IS:===>%d",b);
getch();
}
Write a program to find maximum and minimum numbers from two numbers by using conditional
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("ENTER THE VALUE OF A:===>");
scanf("%d",&a);
printf("ENTER THE VALUE OF B:===>");
scanf("%d",&b);
if(a>b)
{
printf("\n %d IS LARGEST",a);
printf("\n %d IS SMALLEST",b);
}
else if(b>a)
{
printf("\n %d IS LARGEST",b);
printf("\n %d IS SMALLEST",a);
}
else
printf("\n %d and %d both are EQUAL",a,b);
getch();
}
getch();
}
PRACTICAL SET : 3
Write a program to check whether the entered number is odd or even by using if else statement.
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
return 0;
}
Write a program to check whether entered character is alphabet, digit or special symbol.
#include <stdio.h>
int main()
{
char ch;
/* Alphabet check */
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is alphabet.", ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("'%c' is digit.", ch);
}
else
{
printf("'%c' is special character.", ch);
}
return 0;
}
return 0;
}
Write a program to check how many days are there in entered month by using switch case.
#include <stdio.h>
int main()
{
int month;
printf("Enter month number(1-12): ");
scanf("%d", &month);
switch(month)
{
case 1:
printf("31 days");
break;
case 2:
printf("28/29 days");
break;
case 3:
printf("31 days");
break;
case 4:
printf("30 days");
break;
case 5:
printf("31 days");
break;
case 6:
printf("30 days");
break;
case.
int main()
{
char ch;
void main()
{
int num1, num2, num3;
int main()
{
int counter=1;
int n;
printf("Enter the value of n: ");
scanf("%d",&n);
START:
printf("%d ",counter);
counter++;
if(counter<=n)
goto START;
return 0;
}
START:
printf("%d ",counter);
sum=sum+counter;
counter++;
if(counter<=n)
goto START;
printf(" The sum is %d", sum);
return 0;
}
while (originalNum != 0) {
remainder = originalNum % 10;
result += remainder * remainder * remainder;
originalNum /= 10;
}
if (result == num)
printf("%d is an Armstrong number.", num);
else
printf("%d is not an Armstrong number.", num);
return 0;
}
#include <stdio.h>
int main() {
int n, reversedN = 0, remainder, originalN;
printf("Enter an integer: ");
scanf("%d", &n);
originalN = n;
while (n != 0) {
remainder = n % 10;
reversedN = reversedN * 10 + remainder;
n /= 10;
}
if (originalN == reversedN)
printf("%d is a palindrome.", originalN);
else
printf("%d is not a palindrome.", originalN);
return 0;
}
if (n == 1) {
printf("1 is neither prime nor composite.");
}
else {
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
}
return 0;
}
PRACTICAL SET : 5
Write a program to print Different pattern using For Loop.
1
12
123
1234
12345
#include<stdio.h>
main()
{
int i,j,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
}
1
22
333
4444
55555
#include<stdio.h>
main()
{
int i,j,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
}
*****
****
***
**
*
#include<stdio.h>
main()
{
int i,j,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
}
1
12
123
1234
12345
#include<stdio.h>
main()
{
int i,j,k,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=1;k<=n-i;k++)
{
printf(" "); /* For extra Spaces to print*/
}
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
}
*
**
***
****
*****
****
***
**
*
#include<stdio.h>
main()
{
int i,j,k,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
}
A
23
DEF
78910
KLMNO
#include<stdio.h>
main()
{
int i,j,count=1,n;
char ch='A';
printf("Enter the value of N:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(i%2==1)
{
printf("%c",ch);
}
else
{
printf("%d",count);
}
ch++;
count++;
}
printf("\n");
}
PRACTICAL SET : 6
Write a program to print 1 to 5 numbers using array.
#include<stdio.h>
main()
{
int i,a[5];
for(i=0;i<5;i++)
{
a[i]=i+1;
}
for(i=0;i<5;i++)
{
printf("%d\t",a[i]);
}
main()
{
int i,a[5];
for(i=0;i<5;i++)
{
a[i]=5-i;
}
for(i=0;i<5;i++)
{
printf("%d\t",a[i]);
}
main()
{
int i,a[5],sum=0;
float average;
for(i=0;i<5;i++)
{
printf("Enter Value:");
scanf("%d",&a[i]);
sum=sum+a[i];
}
average=sum/5.0;
printf("Sum=%d\tAverage=%f",sum,average);
}
Write a program to find maximum and minimum number from given array.
#include<stdio.h>
main()
{
int i,a[100],n,max,min;
Write a program to find number of positive, negative and zero from given array.
main()
{
int i,a[100],n,pos=0,neg=0,z=0;
for(i=0;i<n;i++)
{
if(a[i]>0)
pos++;
else if(a[i]<0)
neg++;
else
z++;
}
printf("Positive=%d\tNegative=%d\tZeros=%d",pos,neg,z);
}
Write a program to find number of odd and even from given array.
#include<stdio.h>
main()
{
int i,a[100],n,odd=0,even=0;
for(i=0;i<n;i++)
{
if(a[i]%2==0)
even++;
else
odd++;
}
printf("Odd=%d\tEven=%d",odd,even);
}
main()
{
int i,j,k,a[100],n,temp;
main()
{
int i,j,a[10][10],r,c;
}
printf("Transpose of Matrix:\n");
for(i=0;i<c;i++)
{
PRACTICAL SET : 7
Write a program to copy, reverse, concatenate and find length of a string.
#include<stdio.h>
#include<string.h>
int main()
{
char name1[20],name2[20];
int len;
printf("Enter any name:");
//scanf("%s",name1); // first way to get string
gets(name1); // second way to get string
printf("\nName 1 is ==>%s",name1);
// Copy string
strcpy(name2,name1);
printf("\n\nAfter coping name1 into name2");
printf("\nName 1 is ==>%s",name1);
printf("\nName 2 is ==>%s",name2);
// reverse String
strrev(name2);
printf("\n\nAfter reverse name2");
printf("\nName 2 is ==>%s",name2);
//concatenate String
strcat(name1,name2);
printf("\n\nAfter concatenate name1 and name2");
printf("\nName 1 is ==>%s",name1);
printf("\nName 2 is ==>%s",name2);
//length of string
len=strlen(name1);
Write a program to find length of given string without using string function.
#include<stdio.h>
int main()
{
char str[20];
int len;
printf("Enter any name:");
scanf("%s",str);
printf("\nString is ==>%s",str);
for(len=0;str[len]!='\0';)
len++;
printf("\n\nLength of '%s' is ==>%d",str,len);
return 0;
}
Write a program to copy one string to another string without using string function.
#include<stdio.h>
int main()
{
char str[20],str1[20];
int i;
printf("Enter any name:");
scanf("%s",str);
printf("\nString is ==>%s",str);
for(i=0;str[i]!='\0';i++)
str1[i]=str[i];
str1[i]='\0'; //put null character at the end of string
printf("\n\nAfter coping name1 into name2");
printf("\nName 1 is ==>%s",str);
printf("\nName 2 is ==>%s",str1);
return 0;
}
int main()
{
char str[20],str1[20];
int i;
printf("Enter First name:");
gets(str);
printf("Enter Second name:");
gets(str1);
printf("\nFirst name is ==>%s",str);
printf("\nSecond name is ==>%s",str1);
for(i=0;(str[i]!='\0')&&(str[i]==str1[i]);i++);
if(str[i]=='\0'&&str1[i]=='\0')
printf("\n\nBoth name are same\n");
else
printf("\n\nBoth name are not same\n");
return 0;
}
strcpy(str1,str);
strrev(str1);
printf("\nName is ==>%s",str);
printf("\nReverse Name is ==>%s",str1);
for(i=0;(str[i]!='\0')&&(str[i]==str1[i]);i++);
if(str[i]=='\0'&&str1[i]=='\0')
printf("\n\nName is Palindrome\n");
else
printf("\n\nName is not Palindrome\n");
return 0;
}
for(i=0;str[i]!='\0';i++)
{
str1[i]=toupper(str[i]);
}
PRACTICAL SET : 8
Write a user defined function (UDF) to print whether entered number is odd or even.
#include<stdio.h>
#include<conio.h>
void oddeven(int);
void main()
{
int n;
clrscr();
printf("\n Enter number::");
scanf("%d",&n);
oddeven(n);
getch();
}
void oddeven(int n)
{
if(n%2==0)
{
printf("\n Even number...");
}
else
{
printf("\n Odd number...");
}
}
Write a program to add first n numbers using user defined function (UDF).
#include<stdio.h>
#include<conio.h>
int sum(int);
void main()
{
int num,ans=0;
clrscr();
printf("\n Enter the number you want to add upto::");
scanf("%d",&num);
ans=sum(num);
printf("\n The sum of %d numbers is %d...",num,ans);
getch();
}
int sum(int num)
{
int add=0;
while(num!=0)
{
add=add+num;
num--;
}
return add;
}
Write a program to find out average of first n numbers using user defined function (UDF).
#include<stdio.h>
#include<conio.h>
float average(int);
void main()
{
int num;
float ans;
clrscr();
printf("\n Enter the number you want to find average upto::");
scanf("%d",&num);
ans=average(num);
printf("\n The average of first %d numbers is %.2f...",num,ans);
getch();
}
float average(num)
{
int add=0,oldn=num;
float avg;
while(num!=0)
{
add=add+num;
num--;
}
avg=(float)add/oldn;
return avg;
PRACTICAL SET : 9
Write a program using structure to get name, roll number, and marks of a student’s of a class and
#include<stdio.h>
#include<conio.h>
struct student
{
int roll,marks;
char name[10];
};
void main()
{
struct student s[3];
int max=0,i,r;
clrscr();
for(i=0;i<=2;i++)
{
printf("\n Enter student name:");
scanf("%s",s[i].name);
printf("\n Enter roll no:");
scanf("%d",&s[i].roll);
printf("\n Enter marks::");
scanf("%d",&s[i].marks);
if(s[i].marks>max)
{
max=s[i].marks;
r=i;
}
}
printf("\n Details of student having maximum marks is:\nName: %s \nRoll no: %d\n Marks:
%d",s[r].name,s[r].roll,s[r].marks);
getch();
Write a program to enter the details (Name, Employee_id, Salary) of employees using the concept of
#include<conio.h>
struct employee
{
int id;
char name[10];
struct salary
{
int basic,DA;
}sal;
}emp;
void main()
{
int total;
clrscr();
printf("\n *** Details of Employee ***");
printf("\n Name of employee:");
scanf("%s",emp.name);
printf("\n Employee id:");
scanf("%d",&emp.id);
printf("\n Basic and DA::");
scanf("%d \n %d",&emp.sal.basic,&emp.sal.DA);
total=emp.sal.basic+emp.sal.DA;
printf("\n Total salary is %d",total);
getch();
}
Write a program to create an employee structure having member’s name, salary, Get data in
employee structure through one function and display data using another function. Use the concept
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct Member
{
int salary;
char name[10];
};
struct Member get_data(struct Member mem);
void print_data(struct Member mem);
void main()
{
struct Member mem,mem_new;
clrscr();
printf("\n *** Details of member ***");
mem_new=get_data(mem);
print_data(mem_new);
getch();
}
struct Member get_data(struct Member mem)
{
printf("\n Enter Member name:");
scanf("%s",mem.name);
printf("\n Enter salary:");
scanf("%d",&mem.salary);
return mem;
}
void print_data(struct Member mem)
{
printf("\n Member having name %s got %d salary...",mem.name,mem.salary);
PRACTICAL SET : 10
Write a program to declare and use pointer variables.
#include<stdio.h>
#include<conio.h>
void main()
{
int p=100,*ptr;
clrscr();
ptr=&p;
printf("\n\n\nValue Of P===>%d and %d",p,*ptr);
printf("\n\n\nAdress Of P===>%u and %u",&p,ptr);
getch();
}
Write a program to swap two values with help of call by value and call by reference.
#include<stdio.h>
#include<conio.h>
void change(int *,int *);
void swap(int,int);
void main()
{
int a,b;
clrscr();
printf("\n\nEnter the a:===>");
scanf("%d",&a);
printf("\n\nEnter the b:===>");
scanf("%d",&b);
change(&a,&b);
printf("\n\nSwaping With Call By Reference\n\n");
printf("Change Value Of A = %d and B = %d",a,b);
swap(a,b);
getch();
}
void change(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void swap(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
Write a program to find length of string using pointer and without using string functions.
#include<conio.h>
len=string_len(s);
printf("\nLength of string = %d ",len);
getch();
}
PRACTICAL SET : 11
Write a program to write the characters into file from standard input and then read the characters
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char c;
clrscr();
fp=fopen("input","w");
while((c=getc(stdin))!=EOF)
{
putc(c,fp);
}
fclose(fp);
fp=fopen("input","r");
while((c=getc(fp))!=EOF)
putc(c,stdout);
getch();
}
Write a program that copies the contents of one file into another.
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp1,*fp2;
char c;
clrscr();
fp1=fopen("input","r");
fp2=fopen("output","w");
while((c=getc(fp1))!=EOF)
putc(c,fp2);
printf("File copied");
fclose(fp1);
fclose(fp2);
getch();
}
Write a program that appends the content of a file at the end of the other.
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char c;
clrscr();
fp=fopen("input","a");
while((c=getchar())!=EOF)
{
putc(c,fp);
}
fclose(fp);
fp=fopen("input","r");
while((c=getc(fp))!=EOF)
putc(c,stdout);
fclose(fp);
getch();
}