Bca Iind Sem Program
Bca Iind Sem Program
#include<stdio.h>
#include<conio.h>
int main()
{
int Size, i, SUHAIL[Size];
int Even_Count = 0, Odd_Count = 0;
printf("\n Please Enter the Size of an Array : ");
scanf("%d", &Size);
printf("\nPlease Enter the Array Elements\n");
for(i = 0; i < Size; i++) {
scanf("%d", &SUHAIL[i]);
}
for(i = 0; i < Size; i ++) {
if(SUHAIL[i] % 2 == 0) {
Even_Count++;
} else {
Odd_Count++;
}
}
printf("\n Total Number of Even Numbers in this Array =%d ",
Even_Count); printf("\n Total Number of Odd Numbers in this
Array = %d ", Odd_Count); return 0;
}
Output:
Please Enter the Size of an Array : 6
Please Enter the Array Elements
2
4
1
6
8
3
7
Total Number of Even Numbers in this Array = 4
Total Number of Odd Numbers in this Array = 2
2. WAP in c Lang input N element in array & print max & min
elements.
#include <stdio.h>
#include <conio.h>
int main()
{
int SUHAIL[Size],i,n,min,max;
printf("Enter size of the array : ");
scanf("%d",&Size);
printf("Enter elements in array :
");
for(i=0; i<Size; i++)
{
scanf("%d",&SUHAIL[i]);
}
min=max=SUHAIL[0];
for(i=1; i<n; i++)
{
if(min>a[i])
min=a[i];
if(max<a[i])
max=a[i];
}
2
printf("minimum of array is : %d",min); printf("\
nmaximum of array is : %d",max);
return 0;
}
Output:
Enter size of the array : 5
Enter elements in array : 11
44
5
1 100 minimum of array is : 1
maximum of array is : 100
3
for(j=0;j<col;j++)
{
scanf("%d",&SUHAIL[i][j]);
}
}
printf("The matrix\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",SUHAIL[i][j]);
}
printf("\n");
} //To add diagonal elements
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(i==j)
{
sum=sum+SUHAIL[i][j];
}
}
}
printf("The sum of diagonal elements of a square matrix = %d\
n",sum);
}
Output:
Enter the number of rows and columns for 1st matrix
4
2
2
Enter the elements of the matrix
1
2
3
4
The matrix
1 2
3 4
The sum of diagonal elements of a square matrix = 5
4. Wap in C Lang input N elements in array & insert one elements with
given position.
Code:
#include<stdio.h>
#include<conio.h>
#define size 100
int i;
void insert(int SUHAIL[],int s);//fun
prototype void main()
{
int SUHAIL[size],s;
printf("\n how many element store in array=");
scanf("%d",&s);
printf("enter the %d elements=\n",s);
for(i=0;i<s;i++)
5
{
scanf("%d",&SUHAIL[i]);
}
insert(SUHAIL,s);//fun calling
}
void insert(int SUHAIL[],int s)//fun defination
{ int n,p;
printf("enter
the insert
elements and
its
position=");
scanf("%d
%d",&n,&p);
--p; for(i=s;i>=p;i--)
{
SUHAIL[i+1]=SUHAIL[i];
}
SUHAIL[
p]=n; s++;
printf("\n new array after insert the element=\n");
for(i=0;i<s;i++)
{
printf("%4d,",SUHAIL[i]);
}
}
6
Output:
2
4
5
6
7
5. Wap in c Lang input N element in array & print ascending
order(bubble sort).
Code:
#include<stdio.h>
#include<conio.h>
#define size 100 int i;
Void sort(int SUHAIL[],int s);//fun prototype
void main()
{
int SUHAIL[size],s;
printf("\n No. of elements store in array=");
scanf("%d",&s);
printf("enter the %d elements=\n",s);
for(i=0;i<s;i++)
{
scanf("%d",&SUHAIL[i]);
}
sort(SUHAIL,s);//fun calling
}
void sort(int SUHAIL[],int s)// fun defination
{ int
j,c;
for(i=0;i<s;i++)
{
for(j=i+1;j<s;j++)
8
{
if(SUHAIL[i]>SUHAIL[j])
{
c=SUHAIL[i]; SUHAIL[i]=
[j];
SUHAIL[j]=c;
}
}
}
printf("the array in ascending order=\n");
for(i=0;i<s;i++)
{
printf("%4d,",SUHAIL[i]);
}
}
Output:
No. of elements store in array=5 enter the
5 elements=
23
56
11
scanf("%d", &SUHAIL[i]);
}
10
{
if(SUHAIL
[middle]<search) first = middle+1;
else if(SUHAIL [middle]==search)
{
printf("\nThe number, %d found at Position %d",
search, middle+1); break;
}
else last = middle-1;
middle = (first+last)/2;
}
if(first>last)
printf("\nThe number, %d is not found in given Array",
search);
getch();
return 0;
}
Output:
Enter the size of array 6
Enter elements (in ascending order): 55 66 77 88 99 199
Enter element to be search: 77
#define row 10
#define column 10
void main()
{
int SUHAIL [row][column],r,c,i,j;
for(j=0;j<c;j++)
{
printf("\n the cordinate [%d,%d]=",i,j);
scanf("%d",&SUHAIL [i][j]);
}
}
printf("\n the given matrix is:-\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%4d",SUHAIL [i][j]);
12
} printf("\n");
}
printf("\n the transpose of matrix :-\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%4d", SUHAIL [j][i]);
}
printf("\n");
}
Output:
enter the no of row and column first matrix=2 2 enter the
matrix 4 elements
the cordinate [0,0]=1
#define row 10
#define col 10
void main()
{
int SUHAIL[row][col],verma [row][col],SUHAIL
[row][col],row1, col1,row2,col2,i,j;
14
printf("Enter the first matrix %d elements",row1*col1);
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
printf("\n the coordinate [%d,%d]=",i,j); scanf("%d",&SUHAIL[i][j]);
}
}
printf("enter the second matrix %d elements",row2*col2);
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
{
printf("\n the coordinate[%d,%d]=",i,j); scanf("%d",&verma [i]
[j]);
}
}
printf("\n the first matrix elements\n");
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
printf("%4d",SUHAIL[i][j]);
}
printf("\n");
15
printf("\n the second matrix elements\n");
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
{ printf("%4d", [i][j]);
} printf("\n");
}
printf("\n the addition of two matrix elements\n");
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
SUHAIL[i][j]=SUHAIL[i][j]+ [i][j];
printf("%4d",SUHAIL [i][j]);
} printf("\n");
}
}
Output:
enter the no of row and column first matrix=2 2 enter the no
of row and column second matrix=2 2
Enter the first matrix 4 elements
the coordinate[1,1]=4
10 17
8 7
#define row 10
#define col 10
void main()
{
17
int SUHAIL[row][col], varma [row][col],SUHAIL
[row][col],row1, col1,row2,col2,i,j,k;
18
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
printf("%4d",SUHAIL[i][j]);
} printf("\n");
}
printf("\n the second matrix elements\n"); for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
{ printf("%4d", varma [i][j]);
} printf("\n");
}
printf("\n the multiplication of two matrix elements\n");
for(i=0;i<row1;i++)
{
for(j=0;j<col2;j++)
{
SUHAIL
[i][j]=0;
for(k=0;k<col1;k++)
{
SUHAIL [i][j]=SUHAIL [i][j]+SUHAIL[i][k]* varma
[k][j]; }
printf("%4d",SUHAIL [i][j]);
}
printf("\n");
19
}
}
Output:
enter the no of row and column first matrix=2 2
enter the no of row and column second matrix=2 2
Enter the first matrix 4 elements the
coordinate [0,0]=2
the coordinate [0,1]=4
the coordinate [1,0]=6
the coordinate[1,0]=5
the coordinate[1,1]=7
for(j=0;j<5;j++)
{ if(i>j)
{
printf("%4d",-1);
} if(i<j)
{
printf("%4d",+1);
} if(i==j)
{
printf("%4d",0);
}
} printf("\n");
21
}}
Output:
0111 1
-1 0 1 1 1
-1 -1 0 1 1
-1 -1 -1 0 1
-1 -1 -1 -1 0
11. Wap in c Lang to read a Matrix and find out the max element and
its position in the matrix.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int SUHAIL[10][10],i,j,k,max,row,col;
printf("enter the no of row and colume for the matrix ");
scanf("%d%d",&row,&col);
printf("enter the matrix elements=%d",row*col);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&SUHAIL[i][j]);
}
22
}
max=SUHAIL[0][0];
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if( SUHAIL[i][j]>max)
{
max=SUHAIL[i][j];
}}}
printf("the max elements in given matrix=%d",max);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(max==SUHAIL[i][j])
printf("the elements found at position=[%d,%d]",i+1,j+1);
break;
}
}
}
Output:
enter the no of row and colume for the matrix 2 2 enter the
matrix elements=4
23
23
56
78
99
the max elements in given matrix=99
24
printf("The value of a and b Inner fun calling a=%dand
b=%d",*a,*b);
printf("\n");
}
Output:
Enter the value of a and b=45 100
The value of a and b before swapping a=45and b=100 The value
of a and b Inner fun calling a=100and b=45
The value of a and b after swapping a=100and b=45
{
int *p, i, n;
p = (int*)calloc(n, sizeof(int));
if(p==NULL)
{
printf("Memory allocation failed"); exit(1);
}
25
for(i = 0; i < n; i++)
{
printf("Enter %d element: ", i);
scanf("%d", p+i);
}
1357
14. Wap in c Lang input any string with malloc & change size with
realloc function.
Code:
#include<stdio.h>
#include<conio.h>
26
#include<string.h>
void main()
{
char *str; str=(char *)malloc(30*sizeof(char));
strcpy(str,"SUHAIL"); printf("the string %s store at
address=%u",str,str); str=(char *) realloc(str,90); printf("\
n");
printf("Enter the string after reallocating its size=");
scanf("%s",str); printf("\n the string %s store at address=
%u",str,str); free(str);
}
Output:
the string SUHAIL store at address=12260368
Enter the string after reallocating its size=SUHAIL
the string SUHAIL store at address=12260368
15. Wap in C Lang count vowel char given string.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{ int c=0,i,l; char str[20];
printf("Enter the string=");
gets(str); l=strlen(str);
For(i=0;i<l;i++)
{
If(srt==[i]’á’|str==[i]’e’|
27
for(i=0;i<l;i++)
{
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'|| str[i]=='u')
c++;
}
printf("The vowel character given string=%d",c); } Output:
Enter the string=egg
The vowel character given string=1
28
{
17. Wap in C Lang input any string and print it length with user
define function & passing argument.
Code:
#include<stdio.h>
#include<conio.h>
#define size 100
Void main ()
int i; int strlen(char *str); //fun prototype
{
29
char str[size];
30
}
Output:
Enter any string for calculating its length =SUHAIL The length
of string=11
18. Wap in C Lang copy one string two another string with user
define function & passing argument.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define size 100
Void main()
int i;
void strcopy(char *SUHAIL); //fun prototype
{
char SUHAIL[size];
printf("Enter any string =\n");
gets(SUHAIL);
{
31
char
SUHAILcopy[size];
int l=0,p=0;
printf("the first
string=%s",SUHAIL);
for(i=0;
SUHAIL[i]!='\0';i++)
{ l++; }
for(i=0;i<=l;i++)
{
SUHAILcopy[p]=SUHAIL[i]; p++;
}
printf("\nthe second new string=%s",SUHAILcopy);
}
Output:
Enter any string = SUHAIL the first
string=SUHAIL the second new
string=SUHAIL
32
19. Wap in C Lang compare two string with user define function &
passing argument.
Code:
#include<stdio.h>
#include<conio.h>
#define size 100
int i;
void main ()
void strcompare(char
*SUHAIL);
{
char SUHAIL[size];
printf("enter the first string =");
gets(SUHAIL);
strcompare(SUHAIL);
}
void strcompare(char *SUHAIL)
{
char newSUHAIL[size];
int j,f=0; printf("The first
string=%s",SUHAIL);
printf("\n");
printf("Enter the second string=");
gets(newSUHAIL);
for(i=0,j=0;SUHAIL[i]!='\0',newSUHAIL[j]!='\
0';i++,j+)
{
if (SUHAIL[i]!=newSUHAIL[j])
33
{ f=1;
break;
}
} if(f==0)
printf("\n Both string are same\n");
else
printf("\n Both string are not same");
}
Output:
enter the first string =SUHAIL
The first string=SUHAIL
Enter the second
string=SUHAIL Both string
are same
34
20. Wap in C Lang concatenation two string with user define
function & passing argument.
Code:
#include<stdio.h>
#include<conio.h>
#define size 100
int i;
void strconcatenat(char *SUHAIL1); //fun prototype void
main()
{
char SUHAIL1[size];
printf("enter the first string =");
gets(SUHAIL1);
strconcatenat(SUHAIL1); //fun calling
}
void strconcatenat(char *SUHAIL1)//fun defination
{
char
SUHAIL2[size],newstr[size]; int j;
printf("the first
string=%s",SUHAIL1);
printf("\nEnter the second string=");
gets(SUHAIL2);
for(i=0;SUHAIL1[i]!='\0';i++)
35
{
newstr[i]=SUHAIL1[i];
}
for(j=0;SUHAIL2[j]!='\0';j++)
{
newstr[i+j] =SUHAIL2[j];
} newstr[i+j]='\0';
printf("the new concatenat two string=%s",newstr);
}
Output:
enter the first string =sd the
first string=sd
Enter the second string=management the new
concatenat two string=sdmanagement
36
21. Wap in c Lang to read a line of text and print the no of
occurrences of a given substring.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h> void
main()
{
char a[]="SD management SD college of pharmacy SD group
of college SD college of law",c[10]="SD"; int l,cu=0;
l=strlen(c); while(1)
{
if(strstr(a,c)==NULL)
break;
strcpy(a,strstr(a,c));
strcpy(a,a+l); cu++;
}
printf("the sub string found occurance=%d",cu);
}
Output: the sub string found
occurance=4
37
22. wap in c lang input any string reverse all the word.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char
SUHAILstr[100],rev[100]; int i,j=0;
printf("Enter any string=");
gets(SUHAILstr);
for(i=0;SUHAILstr[i]!='\0'; i++)
{
if(SUHAILstr[i]!=' ')
{
rev[j]=SUHAIL
str[i]; j++;
}
else
{
SUHAILstr[j]='\0';
printf("%s",strrev(rev));
printf(" "); j=0;
} } rev[j]='\0';
printf("%s",strrev(rev));
}
Output:
38
Enter any string=myself flesym
gets(SUHAIL); n =
strlen(SUHAIL); for
(i=0; i<=n; i++)
{ for (j=i+1; j<n; j++)
{
if (SUHAIL[i] > SUHAIL[j])
{
temp = SUHAIL[i];
SUHAIL[i] =
SUHAIL[j]; SUHAIL[j]
= temp;
39
}
}}
printf("\n%s", SUHAIL);
printf("\n");
}
Output:
Enter string for sorting: edcba
abcde
41
printf("The sorted string\n");
for(i=0;i<=n;i++) puts(SUHAIL[i]);
}
Output:
Enter the no. of string to be sorted
3 zebra
mango
apple
The sorted string
apple mango
zebra
42
}o[10]; void
main()
{
int ch,i,c,n,sacno,damount,wamount; do
{
printf("\n====================**************************===
=================\n");
printf("\n Press 1 to ADD CUSTOMER");
printf("\n Press 2 to DISPLAY ALL THE RECORDS");
printf("\n Press 3 to DEPOSITE AMOUNT");
printf("\n Press 4 to WITHDRAW AMOUNT");
printf("\n Press 5 to SEARCH RECORDS");
printf("\n Press 6 to EXIT");
printf("\n");
printf("\n");
printf("\n====================**************************===
=================\n");
printf("\n ENTER YOUR CHOICE=");
scanf("%d",&ch); switch(ch)
{
case 1:
printf("Enter the number of customer to be added=");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the Account Number=");
43
scanf("%d",&o[i].acno);
printf("Enter the Account Holder Name=");
fflush(stdin);
scanf("%s",o[i].name);
printf("Enter the Account's Holder Father's name=");
fflush(stdin);
scanf("%s",o[i].fname);
printf("Enter the City Name=");
fflush(stdin);
scanf("%s",o[i].city);
printf("Enter the Account Type(Savings/Current/Fixed
Deposite)=");
fflush(stdin);
scanf("%s",o[i].type);
printf("Enter the Starting Amount=");
fflush(stdin);
scanf("%d",&o[i].amount);
}
break; case 2:
printf("\n THE CUSTOMER INFORMATION : \n");
for(i=0;i<n;i++)
{
printf("\n The Account no. is =%d",o[i].acno);
printf("\n The Account Holder name =%s",o[i].name);
printf("\n The Account Holder's father name
=%s",o[i].fname);
44
printf("\n The City name =%s",o[i].city);
printf("\n The Account Type =%s",o[i].type);
printf("\n The Amount =%d",o[i].amount);
}
break;
case 3:
printf("enter the accno no for deposited amount ");
scanf( "%d",&sacno);
for(i=0;i<n;i++)
{
if(o[i].acno==sacno)
{
printf("enter the amount");
scanf("%d",&damount);
o[i].amount=o[i].amount+damount;
}
}
printf("the successfully deposited amount");
break; case 4:
printf("enter the accno no for withdrow amount");
scanf( "%d",&sacno);
for(i=0;i<n;i++)
{
if(o[i].acno==sacno)
45
{
printf("enter the withdrow amount");
scanf("%d",&wamount); if(wamount>o[i].amount)
{
{
printf("\n The Account no. is =%d",o[i].acno);
printf("\n The Account Holder name =%s",o[i].name);
printf("\n The Account Holder's father name
46
=%s",o[i].fname);
printf("\n The City name =%s",o[i].city);
printf("\n The Account Type =%s",o[i].type);
47
====================**************************==========
==========
====================**************************==========
==========
48
Press 5 to SEARCH RECORDS
Press 6 to EXIT
====================**************************==========
==========
49
struct position
{ float
m,s,c,h,e,t,p; }o2;//
inner object
}o1;//outer object
void main()
{
printf(" Enter the Roll no. of student=");
scanf("%d",&o1.rollno);
printf(" Enter the name of student=");
fflush(stdin);
gets(o1.studentname);
printf(" Enter the course of student=");
fflush(stdin); gets(o1.course);
printf(" Enter the marks of all 5 subject marks=");
scanf("%f%f%f%f
%f",&o1.o2.m,&o1.o2.s,&o1.o2.c,&o1.o2.h ,&o1.o2.e);
o1.o2.t=o1.o2.m+o1.o2.s+o1.o2.s+o1.o2.c+o1.o2.h+o1.o2.e;
o1.o2.p=(o1.o2.t*100)/500; printf("\n\
n************************************************");
printf("\n The Roll no. of student =%d",o1.rollno);
printf("\n The name of student =%s",o1.studentname);
printf("\n The course name of student =%s",o1.course);
printf("\n The total marks of student =%f",o1.o2.t);
printf("\n The total percentage of student =%f",o1.o2.p);
printf("\n\n************************************************"); }
50
Output:
Enter the Roll no. of student=185 Enter
the name of student=SUHAIL Enter the
course of student=B.C.A
Enter the marks of all 5 subject marks=80 70 85 90 85
************************************************
The Roll no. of student =185
The name of student =SUHAIL
The course name of student =B.C.A
The total marks of student =480.000000
The total percentage of student =96.000000
************************************************
51
27. Wap in c Lang to used the bitwise operator.
Code:
#include<stdio.h> void
main()
{ int a,b,choice;
do
{ printf("\n\n********** MENU **********"); printf("\n Press
1 to calculate Bitwise AND operator:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n Enter the value of a and b=");
scanf("%d%d",&a,&b);
printf("The output of the Bitwise AND operator
a&b is %d",a&b); break;
case 2:
printf("\n Enter the value of a and b=");
scanf("%d%d",&a,&b);
52
printf("The output of the Bitwise OR operator
a&b is %d",a|b); break;
case 3:
b>>2);
case 6:
printf("Goodbye\n");
break;
default:
printf("Wrong Choice. Enter again\n");
break;
} }while(choice!=6);
}
Output:
54
Enter your choice:1
57
********** MENU **********
Press 1 to calculate Bitwise AND operator:
Press 2 to calculate Bitwise OR operator:
Press 3 to calculate Bitwise exclusive OR operator:
Press 4 to calculate Bitwise complement operator:
Press 5 to calculate Bitwise shift operators:
Press 6 for exit
28. Wap to read data from keyboard & write to a file “input” again
read the same data from the input file and display on the string.
Code:
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp; char c;
fp=fopen("input.txt","w");
printf("\n data input=");
While
((c=getchar())!= EOF)
{
putc(c,fp);
}
fclose(fp);
58
fp=fopen("input.txt","r");
printf("\nData stored in the file input.txt is as follows\n");
while((c=getc(fp))!=EOF)
{
printf("%c",c);
}
fclose(fp);
}
Output:
data input=SUHAIL
^Z
29. Wap in C Lang count char, space, tabs and new lines in a file.
Code:
#include<stdio.h>
#include<conio.h> void
main()
{
59
FILE *fp; char ch , fname[40]; int
nol=0,not=0,nos=0,noc=0;
printf("Enter file name : ");
gets(fname);
fp = fopen(fname, "r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break; noc++;
if(ch==' ') nos++;
if(ch=='\n') nol++;
if(ch=='\t') not++;
}
fclose(fp); printf("\n Number of characters =
%d",noc); printf("\n Number of blanks =
%d",nos); printf("\n Number of tabs = %d",not);
printf("\n Number of lines = %d",nol);
}
Output:
Enter file name : file29.txt
60
Number of characters = 90
Number of blanks = 12
Number of tabs = 0
Number of lines = 7
if(fp1==NULL)
{
printf("first file does not exist in the system");
getch(); exit(0);
}
if(fp2==NULL)
{
printf("second file does not exist in the system");
61
getch();
exit(0);
}
c1 = getc(fp1);
c2 = getc(fp2);
while ((c1 != EOF) && (c2 != EOF) && (c1 == c2))
{
c1 = getc(fp1); c2 =
getc(fp2);
} if (c1 == c2)
printf("Yesss !!!! Files are identical");
else
printf("Noooo !!!! Files are Not identical");
fclose(fp1);
fclose(fp2);
getch();
}
Output:
First text file is SUHAIL.txt which contain text is Okay
Second text file is varma .txt which contain text is Okay
62
31. Wap in c lang count no of word in text file.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{ char ch;
return 0;
}
Output:
63
Number of words present in given file: 6
sum+=atoi(argv[i]);
}
}
printf("\n Sum of all command line arguments is %d \n
\n",sum);
}
Output:
64
Enter number of arguments to calculate sum
10 20 30
Sum of all command line arguments is 60
33. Wap in c Lang input any string and update with Fseek function.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp; fp=fopen("SUHAIL.c",
"w"); if(fp==NULL)
{
printf("this file does not exit");
exit(0);
}
fputs(" Heyy!!! myself SUHAIL",fp);
fseek(fp,11,0);
fputs("sam",fp);
printf("Text updated successfully");
fclose(fp);
getch();
}
Output:
Text updated successfully
65
34. Wap in C Lang swap two no with used Macro.
Code:
#include<stdio.h>
#include<conio.h>
#define SWAP c=a
Void main ()
a=b, b=c;
{ int a,b,c;
printf("Enter the value of a and b before swapping=");
scanf("%d%d",&a,&b);
SWAP
printf("The value a and b after swapping a=%d & b=%d",a,b);
}
Output:
Enter the value of a and b before swapping=100 400 The value a
and b after swapping a=400 & b=100
END OF PROGRAM
66