C File Shilpi
C File Shilpi
of Advanced Studies
Name:- A r y a n S h a r m a
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
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
Pointer?
11 Write a C program to find the address of any 11
Structure?
13 Write a C Program to Access the members of 13
Structure?
String?
#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();
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();
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
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 main()
int arr[5],i;
clrscr();
for(i=0;i<5;i++)
scanf("%d",&arr[i]);
check(arr[i]);
getch();
return 0;
if(num%2==0)
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: