0% found this document useful (0 votes)
54 views

C File Shilpi

This document contains a practical file submission for a C programming session by a student named Aryan Sharma of Saharanpur Institute of Advanced Studies. The file includes an acknowledgement, declaration, table of contents listing 17 programming problems and their page numbers, and solutions to each of the 17 problems written in C code with outputs. The problems cover topics such as arrays, matrices, functions, pointers, strings and structures.

Uploaded by

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

C File Shilpi

This document contains a practical file submission for a C programming session by a student named Aryan Sharma of Saharanpur Institute of Advanced Studies. The file includes an acknowledgement, declaration, table of contents listing 17 programming problems and their page numbers, and solutions to each of the 17 problems written in C code with outputs. The problems cover topics such as arrays, matrices, functions, pointers, strings and structures.

Uploaded by

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

Saharanpur Institute

of Advanced Studies

Practical File of C Programming


Session 2021-24

Summited By: Summited To:


Aryan Sharma Mr. Vibhor Mittal
(Sem IInd)
ACKNOWLEDGEMENT

It gives me immense pleasure to express my heartfelt to my


respected guide “ Mr. VIBHOR MITTAL”.(faculty of S.I.A.S.) for
providing me articulate guidance and caseless engorgement
throughout my program to me .Despite his numerous pre-
occupation ,he always spread her valuable time to guide me
at all stage of my work. But without her expert guidance and
visionary approach the research work would not have been
completed in the present shape. Word fail me to fully express
my emotions of in deftness to him.

In the last I am thankful to all respondents to cooperate with


me in gathering the data needed for the report . Also I would
like to thank to all those who have been skipped for the
memory and have been the source of inspiration or help or
otherwise.

Name:- A r y a n S h a r m a

Stream:- BCA 1st year


DECLARATION

I hereby you declare that the project tittle “C


PROGRAMING” project file undertaken by me is an
original work. I also declare that this project has not
been submitted to any other institute or university or
anywhere else for academic to fulfil the partial
requirement of the degree of “BCA”.

Date:
Signature:
Sr Page
Programming name No.
no.
01 Write a program to input value into an array and 1

displays them?
02 Write a program to add the elements of an 2

array?
03 Write a program to input an array and count 3

even and odd number?


04 Write a program to input and displays a matrix? 4

05 Write a program for addition of two matrix? 5

06 Write a program to pass array elements to a 6

function?
07 Write a C Program to to find a Address of 7

Pointer?
08 Write a C Program to use Arithmetic Operator in 8

Pointer?
09 Write a C Program to Print a value using Pointer? 9

10 Write a C program to print a Two value using 10

Pointer?
11 Write a C program to find the address of any 11

value using Pointer?

12 Write a C Program Any Two Imaginary digit using 12

Structure?
13 Write a C Program to Access the members of 13

Structure?

14 Write a C program to find the Length of String? 14

15 Write a C Program to Copy one String to Another 15

String?

16 Write a C Program to Reverse the any String 16-


17
Value?

17 Write a C Program to find the Frequency of Any 18-


19
Characters using String?
Q1- Write a program to input value into an array and
displays them?
#include<stdio.h>

#include<conio.h>
void main()
{
int arr[5],i;
clrscr();
for(i=0;i<5;i++)
{
printf("enter the value of array:");
scanf("%d",&arr[i]);
}
for(i=0;i<5;i++)
{
printf("value of array: %d",arr[i]);
printf("\n");
}
getch();

}
Output:-
Q2- Write a program to add the elements of an array?
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum=0,arr[10];
clrscr();

printf("enter the value of array");


for(i=0;i<5;i++)
scanf("%d",&arr[i]);
for(i=0;i<5;i++)
sum=sum+arr[i];
printf("the sum of an array %d\n",sum);
printf("\n");
getch();
}

Output:-
Q3- Write a program to input an array and count even
and odd number?
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[10];
int i,even=0,odd=0;
clrscr();
printf("enter ten no. to check");
for(i=0;i<10;i++)
{
scanf("%d",&arr[i]);
if(arr[i]%2==0)
{
even++;
}
else
{
odd++;
}
}
printf("no.is even are %d\n",even);
printf("no.is odd are %d\n",odd);
getch();
}
Output:-
Q4- Write a program to input and displays a matrix?

#include<stdio.h>

#include<conio.h>
int main()
{
int a[3][3],i,j;
clrscr();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("enter the number[%d][%d]=",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("array is=\n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
{
printf("%d\t",a[i][j]);
}
}
getch();
return 0;
}
Output:-
Q5- Write a program for addition of two matrix?
#include<stdio.h>

#include<conio.h>

int main()

int a[3][3],b[3][3],c[3][3],i,j;

clrscr();

printf("enter first matrix=\n");

for(i=0;i<3;i++)

for(j=0;j<3;j++)

scanf("%d",&a[i][j]);

printf("enter second matrix=\n");

for(i=0;i<3;i++)

for(j=0;j<3;j++)

scanf("%d",&b[i][j]);

}
printf("addition of matrix=\n");

for(i=0;i<3;i++)

printf("\n");

for(j=0;j<3;j++)

c[i][j]=a[i][j]+b[i][j];

printf("%d\t",c[i][j]);

getch();

return 0;

Output:-
Q6- Write a program to pass array elements to a
function?
#include<stdio.h>

#include<conio.h>

int check(int num);

int main()

int arr[5],i;

clrscr();

for(i=0;i<5;i++)

printf("enter a number to check");

scanf("%d",&arr[i]);

check(arr[i]);

getch();

return 0;

int check(int num)

if(num%2==0)

printf("no. is even \n");

else
printf("no. is odd \n");

return 0;

Output:-
Q7- Write a C Program to to find a Address of Pointer?
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5;
clrscr();
printf("a:%d\n",a);
printf("address of a:%p",a);
getch();
return 0;
}

Output:
Q8- Write a C Program to use Arithmetic Operator in
Pointer?
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,add,sub,multi,div;
int *p,*q;
clrscr();
printf("enter the value of a and b=\n");
scanf("%d%d",&a,&b);
p=&a;
q=&b;
add=(*p)+(*q);
sub=(*p)-(*q);
multi=(*p)*(*q);
div=(*p)/(*q);
printf("%d\n%d\n%d\n%d",add,sub,multi,div);
getch();
return 0;
}

Output:
Q9- Write a C Program to Print a value using Pointer?

#include<stdio.h>
#include<conio.h>
void main()
{
int marks[]={10,20,30};
int *point[3],i;
clrscr();
for(i=0;i<3;i++)
{
printf("%d\n", marks[i]);
point[i]= &marks[i];
}
for(i=0;i<3;i++)
{
printf("%d\n",*point[i]);
}
getch();
}

Output:
Q10- Write a C program to print a Two value using
Pointer?
#include<stdio.h>
#include<conio.h>
void swap(int*n1,int*n2);
int main()
{
int num1 =5,num2=10;
clrscr();
swap(&num1,&num2);
printf("num1=%d\n",num1);
printf("num2=%d",num2);
getch();
return 0;
}
void swap (int*n1,int*n2)
{
int temp;
temp= *n1;
*n1= *n2;
*n2=temp;
}

Output:
Q11- Write a C program to find the address of any value
using Pointer?
#include<stdio.h>
#include<conio.h>
void main()
{
int*pa[3];
int i,a=4,b=10,c=15;
clrscr();
pa[0]=&a;
pa[1]=&b;
pa[2]=&c;
for(i=0;i<3;i++)
{
printf("%d\n",pa[i]);
printf("%d\n",*pa[i]);
}
getch();
}

Output:
Q12- Write a C Program Any Two Imaginary digit using
Structure?
#include<stdio.h>
#include<conio.h>
struct complex {
int imag;
float real;
};
struct number{
struct complex comp;
int integer;
}
num1;
int main(){
num1.comp.imag=11;
num1.comp.real=5.25;
clrscr();
num1.integer=6;
printf("imaginary part:%d\n",num1.comp.imag);
printf("real part:%.2f\n",num1.comp.real);
printf("integer:%d",num1.integer);
getch();
return 0;
}

Output:
Q13- Write a C Program to Access the members of
Structure?

#include <stdio.h>
#include <string.h>
struct Person {
char name[50];
int citNo;
float salary;
} person1;

int main()
{
strcpy(person1.name, "Saharanpur Institute of Advanced Studies");
person1.citNo = 1984;
person1. salary = 2500;
printf("Name: %s\n", person1.name);
printf("Citizenship No.: %d\n", person1.citNo);
printf("Salary: %.2f", person1.salary);
getch();
return 0;
}

Output:
Q14- Write a C program to find the Length of String?

#include<stdio.h>
#include<conio.h>
void main()
{
char s[]="programming is fun";
int i;
clrscr();
for(i=0;s[i] !='\0';i++);
printf("length of the string: %d ",i);
getch();
return 0;
}

Output:
Q15-Write a C Program to Copy one String to Another
String?

#include<stdio.h>
#include<conio.h>
int main()
{
char s1[100],s2[100],i;
clrscr();
printf("enter string s1;");
fgets(s1,sizeof(s1),stdin);
for(i=0;s1[i]!='\0';i++){
s2[i]=s1[i];
}
s2[i]='\0';
printf("string s2: %s",s2);
getch();
return 0;
}

Output:
Q16-Write a C Program to Reverse the any String
Value?
#include<stdio.h>
#include<conio.h>
void reverseSentence();
int main()
{
printf("enter a sentence:");
clrscr();
reverseSentence();
getch();
return 0;
}
void reverseSentence(){
char c;
scanf("%c",&c);
if(c!='\n'){
reverseSentence();
printf("%c",c);
}

Output:
Q17-Write a C Program to find the Frequency of Any
Characters using String?
#include<stdio.h>
#include<conio.h>
int main()
{
char str[1000],ch,i;
int count=0;
clrscr();
printf("enter a string=");
fgets(str,sizeof(str),stdin);
printf("enter a character to find its frequency:");
scanf("%c",&ch);
for(i=0; str[i] !='\0'; i++)
{
if(ch==str[i])
++count;
}
printf("frequency of %c = %d",ch,count);
getch();
return 0;
}

Output:

You might also like