Professional Documents
Culture Documents
AN ASSIGNMENT ON :
PROGRAMING IN C LANGUAGE
FROM : B.C.A – 1st YEAR
YEAR: (2022-23)
REGULAR
Guided by : Submitted by :
Mr. Mannu Rawani Anshu Kumar
Singh
(Head of CS Department) (Student B.C.A-1st)
2
ACKNOWLDGEMENT
INDEX
S.no. Objective/Question: Page no. Remarks
PROGRAM
Output of program :-
8
Output of program:-
9
Output of program:-
10
int main() {
int a, b, c;
printf("enter the first number: ");
scanf("%d",&a);
printf("enter the second number: ");
scanf("%d",&b);
printf("enter the third number: ");
scanf("%d",&c);
if (a >= b && a >= c) {
printf("%d is the greatest number\n", a);
} else if (b >= a && b >= c) {
printf("%d is the greatest number\n", b);
} else {
printf("%d is the greatest number\n", c);
}
return 0;
}
11
Output of program:-
12
int main()
{
int n,i,f=1;
printf("\n enter the value: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
f=f*i;
}
printf("\n factorial=%d",f);
return 0;
}
Output of program:-
13
for(j=0;j<3;j++)
{
printf("\t%d",c[i][j]);
}
printf("\n");
}
return 0;
}
14
Output of program:-
15
Output of program:-
16
Output of program:-
19
int main(){
char name[10]="Anshu";
char surname[10]="Singh";
strcat(name,surname);
printf("\n Concated String=%s",name);
return 0;
}
Output of program:-
20
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\n Multiplication of Two Matrix are \n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
21
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
return 0;
}
Output of program:-
22
int main(){
char name1[20] = "Anshu";
char name2[20] = "Singh";
Output of program:-
24
int main() {
char name[20] = "Anshu";
printf("real string: %s\n",name);
strrev(name);
printf("Reversed string: %s",name);
return 0;
}
Output of program:-
25
int main(){
int value =5;
int result = function(value);
printf("%d",result);
return 0;
}
Output of program:-
26
int main(){
int num;
printf("enter a number: ");
scanf("%d",&num);
if (num % 2==0){
printf("%d is even",num);
} else{
printf("%d is odd",num);
}
return 0;
}
Output of program:-
28
int main(){
float p,r,t;
printf("enter the principal amount: ");
scanf("%f",&p);
printf("enter the annual interest rate: ");
scanf("%f",&r);
printf("enter the number of years: ");
scanf("%f",&t);
int main(){
char c;
printf("enter a character: ");
scanf("%c",&c);
int main(){
char str[100];
int i,length =0;
printf("Enter a string: ");
scanf("%s",str);
for (i =0; str[i] !='\0'; i++){
length++;
}
printf("The length of the string is: %d",length);
return 0;
}
Output of program:-
31
int main(){
char str[100];
char *ptr;
printf("enter a string: ");
scanf("%s",str);
ptr =str;
printf("the string is: %s\n",ptr);
printf("the characters of the string are:\n");
while(*ptr !='\0'){
printf("%c ",*ptr);
ptr++;
}
return 0;
}
Output of program:-
32
int main() {
int x=5, y=10;
printf("before swapping: x =%d, y =%d\n",x,y);
swap(&x, &y);
printf("after swapping: x =%d,y =%d\n",x,y);
return 0;
}
Output of program:-
33
#include <stdio.h>
void print_anshu(){
printf("Anshu!\n");
}
int main(){
print_anshu();
return 0;
}
Output of program:-
34
union data{
int i;
float f;
char str[20];
} data;
int main(){
data.i =10;
printf("integer value: %d\n",data.i);
data.f =220;
printf("float value: %f\n",data.f);
strcpy(data.str, "Anshu");
printf("string value: %s\n",data.str);
return 0;
}
Output of program:-
36
int main(){
int x =10, y =20, z =30;
print_numbers(x,y,z);
return 0;
}
Output of program:-
37
}
Output of program:-
38
Output of program:-
40
ptr1 = &a;
ptr2 = &ptr1;
printf("value of a: %d\n",a);
printf("value of a using ptr1: %d\n",*ptr1);
printf("value of a using ptr2: %d\n",**ptr2);
return 0;
}
Output of program:-
42
for(j=0;j<3;j++){
scanf("%d",&a[i][j]);
}
}
printf("\n enter the array of elements are: \n");
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%d\t",a[i][j]);
}
printf("\n");
}
return 0;
}
44
Output of program:-
45
int main(){
int year;
printf("enter a year: ");
scanf("%d",&year);
if(year % 4== 0){
if(year % 100== 0){
if(year % 400== 0){
printf("%d is a leap year",year);
} else{
printf("%d is not a leap year",year);
}
} else{
printf("%d is a leap year",year);
}
} else{
printf("%d is not a leap year",year);
}
return 0;
}
46
Output of programm :-
47
}
return 0;
}
48
Output of program:-
49
printf("\n");
return 0;
}
Output of program:-
51
output of program:-
53
}
return 0;
}
Output of program:-
56
fp=fopen("file1.txt","r");
while(ch!=EOF)
{
ch=fgetc(fp);
printf("%c",ch);
}
return 0;
}
58
Read file:-
output of program:-
59
Copied file:-
61
struct person{
int age;
int weight;
};
int main(){
struct person p =createperson(18,53);
printf("Age=%d,weight=%d\n",p.age,p.weight);
return 0;
}
63
Output of program:-
64
Output of program:-
66
int n,r,c,arm=0;
printf("enter any numbers: ");
scanf("%d",&n);
c=n;
while(n>0)
{
r =n%10;
arm= (r*r*r)+arm;
n=n/10;
}
if(c==arm)
printf("armstrong number");
else
printf("not armstrong number");
return 0;
}
67
Output of program:-
68
}
return 0;
}
Output of program:-
70
int size_s=sizeof(s);
int size_u=sizeof(u);
printf("total memory occuppied by structure variables:
%dbytes\n",size_s);
printf("total memory occupied by union variables:
&%dbytes\n",size_u);
71
return 0;
}
Output of program:-
72
struct student{
char name[30];
int rollno;
float per;
};
int main(){
struct student s1,s2,s3,s4,s5;
int i,j;
for(i=0;i<5;i++)
{
printf("\n enter the name of student: ");
scanf("%s",&s1.name);
printf("\n enter the rollno of student: ");
scanf("%d",&s1.rollno);
printf("\n enter the prcentage of student: ");
scanf("%f",&s1.per);
}
for(i=0;i<5;i++)
{
73
Output of program:-
78
}
return 0;
}
Output of program:-