Sunteți pe pagina 1din 36

Pgm 1 SAJESH S B

10/1/11 ROLL NO: 46

AIM:Write a program to find the average of two numbers

#include<stdio.h>
int main()
{
int a=5;
int b=3;
int c,d;
c=a+b;
d=c/2;
printf("\nSum=%d\n",c);
printf("Average=%d",d);
return 0;
}

/*OUTPUT

Sum=8
Average=4

*/

Pgm:2 SAJESH S B
10/1/11 ROLL NO: 45

AIM:Write a program to accept two numbers from the user and to find
its product

#include<stdio.h>
int main()
{
int a,b;
int c;
printf("Enter 2 numbers to find the product of:\n");
scanf("%d %d",&a,&b);
c=a*b;
printf("Product=%d",c);
return 0;
}

/*OUTPUT

Enter 2 numbers to find the product of:


3
5
Product=15

*/

Pgm:3 SAJESH S B
10/1/11 ROLL NO: 46

AIM:Write a program to accept two numbers from the user and to find
the greatest number

#include<stdio.h>
int main()
{
int a,b;
printf("Enter 2 numbers to find the greatest of:\n");
scanf("%d %d",&a,&b);
if(a>b)
printf("Greatest=%d",a);
else
printf("Greatest=%d",b);
return 0;
}

/*OUTPUT

Enter 2 numbers to find the greatest of:5


3
Greatest=5

*/

Pgm:4(a) SAJESH S B
17/1/11 ROLL NO: 46

AIM:To print the grades f using if-else case

#include<stdio.h>
int main()
{
int n;
printf("Enter the marks obtained:");
scanf("%d",&n);
if(n<40)
printf("Grade is F");
else if(n>=40&&n<50)
printf("Grade is E");
else if(n>=50&&n<60)
printf("Grade is D");
else if(n>=60&&n<70)
printf("Grade is C");
else if(n>=70&&n<80)
printf("Grade is B");
else if(n>=80&&n<90)
printf("Grade is A");
else if(n>=90&&n<=100)
printf("Grade is S");
return 0;
}

/*OUTPUT

Enter the marks obtained:68


Grade is C

*/

Pgm :4(b) SAJESH S B


17/1/11 ROLL NO: 46

AIM:To print grade using switch case

#include<stdio.h>
int main()
{
int a;
printf("\nenter your marks\n");
scanf("%d",&a);
switch (a)
{
case 0 ... 34:printf("\ngrade is E\n");
break;
case 35 ... 49:printf("\ngrade is D\n");
break;
case 50 ... 59:printf("\ngrade is C\n");
break;
case 60 ... 79:printf("\ngrade is B\n");
break;
case 80 ... 100:printf("\ngrade is A\n");
break;
default:printf("invalid");
break;
}
return 0;
}

/* OUTPUT
enter your marks
65
grade is B

/*

Pgm:5 SAJESH S B
17/1/11 ROLL NO: 46

AIM://To accept 2 numbers and perform different operations

#include<stdio.h>
int main()
{
int a,b,c,p;
printf("Enter 2 numbers to do the operation:\n");
scanf("%d %d",&a,&b);
printf("1.To add\n");
printf("2.To subtract\n");
printf("3.To multiply\n");
printf("4.To divide\n");
printf("Enter your choice:");
scanf("%d",&c);
switch(c)
{
case 1:p=a+b;
printf("Sum=%d",p);break;
case 2:p=a-b;
printf("Difference=%d",p);break;
case 3:p=a*b;
printf("Product=%d",p);break;
case 4:p=a/b;
printf("Quotient=%d",p);break;
default:printf("Wrong choice entered");break;
}
return 0;
}

/*OUTPUT
Enter 2 numbers to do the operation:
4
5
1.To add
2.To subtract
3.To multiply
4.To divide
Enter your choice:3
Product=20
*/

Pgm:8 SAJESH S B
1/2/11 ROLL NO: 46

AIM:To print factorial of a number

#include<stdio.h>
int main()
{
int i=1,p=1,n;
printf("Enter the number you want to find the factorial of:");
scanf("%d",&n);
while(i<=n)
{
p=p*i;
i++;
}
printf("Factorial:%d",p);
return 0;
}

/*OUTPUT

Enter the number you want to find the factorial of:4


Factorial:24

*/
Pgm:9(a) SAJESH S B
1/2/11 ROLL NO: 46

AIM:/* To print *
* *
* * * */

#include<stdio.h>
int main()
{
int n,i,j;
printf("Enter the number of lines:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("*\t");
}
printf("\n");
}
return 0;
}

/*OUTPUT

Enter the number of lines:5


*
* *
* * *
* * * *
* * * * *

/*
Pgm:9(b) SAJESH S B
1/2/11 ROLL NO: 46

AIM:/* to print 1
2 3
3 4 5 */

#include<stdio.h>
int main()
{
int n,i,j;
printf("Enter the number of lines:");
scanf("%d",&n);
for(i=1;i<n;i++)
{
for(j=0;j<i;j++)
{
printf("%d\t",(i+j));}
printf("\n");
}
return 0;
}

/*OUTPUT

Enter the number of lines:3


1
2 3
3 4 5

*/
Pgm 10 SAJESH S B
1/2/11 ROLL NO: 46

AIM:To print the exponential series

#include<stdio.h>
#include<math.h>
int main()
{
int i,j,x,n,f=1;
float s=1.0;
printf("Enter the value for limit and value of x:");
scanf("%d %d",&n,&x);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
f=f*j;}
s=s+(pow(x,i)/f);
}
printf("Sum=%f",s);
return 0;
}

/*OUTPUT

Enter the value for limit and value of x:2


5
Sum=18.500000

*/
Pgm 12 SAJESH S B
8/2/11 ROLL NO: 46

AIM:/*To create an int array of n spaces and enter 10 numbers into it


and also print values*/

#include<stdio.h>
int main()
{
int x,i,n,j,a[100];
printf("Enter a value for array limit:");
scanf("%d",&n);
printf("Enter 10 values:\n");
for(i=0;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("The values you have entered are:\n");
for(j=0;j<10;j++)
{
printf("\n%d",a[j]);
}
return 0;
}
/*OUTPUT

Enter a value for array limit:11


Enter 10 values:
12
13
23
24
25
26
27
28
29
30
14
15
The values you have entered are:
12
13
23
24
25
26
27
28
29
30

*/
Pgm 13 SAJESH S B
8/2/11 ROLL NO: 46

AIM:/*WAP to accept an array limit,enter values and print its sum*/

#include<stdio.h>
int main()
{
int i,j,n,s=0;
int a[100];
printf("Enter the array limit:");
scanf("%d",&n);
printf("Enter the numbers in array\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(j=0;j<n;j++)
{ s=s+a[j];}
printf("Sum=%d",s);
return 0;
}

/*OUTPUT

Enter the array limit:5


Enter the numbers in array
1
3
7
5
6
Sum=22

/*
Pgm 14 SAJESH S B
8/2/11 ROLL NO: 46

AIM:/*To search a number in an array and print its position*/

#include<stdio.h>
int main()
{
int i,a[10],s,m,j,k=0;
printf("Enter the array of 10 elements:");
for(i=0;i<10;i++)
{ scanf("%d",&a[i]);}
printf("Enter the number you want to search:");
scanf("%d",&m);
for(j=0;j<10;j++)
{
if(a[j]==m)
{ s=j;
k++;}
}
if(k==0)
printf("the number not found");
}
else
printf("The location of %d is %d",m,s);
return 0;
}

/*OUTPUT

Enter the array of 10 elements:3


4
2
5
1
6
4
3
9
10
Enter the number you want to search:6
The location of 6 is 5

/*

Pgm 15 SAJESH S B
8/2/11 ROLL NO: 46

AIM:/* To sort an array using (a).selection sort (b).bubble sort*/


#include<stdio.h>
int main()
{
int i,a[10],j,min,p,n,temp,ch,t;
printf("Enter the limit of the array:\n");
scanf("%d",&n);
printf("Enter the numbers of the array:\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("1.SORT BY SELECTION SORT TECHNIQUE\n");
printf("2.SORT BY BUBBLE SORT TECHNIQUE\n");
printf("Enter your choice:\n");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("Sorted array:\n");
for(i=0;i<n;i++)
{
min=a[i];
p=i;
for(j=i+1;j<n;j++)
{
if(min>a[j])
{
min=a[j];
p=j;
}
}
temp=a[i];
a[i]=min;
a[p]=temp;
}
for(i=0;i<n;i++)
printf("%d\n",a[i]);break;
case 2: printf("The sorted array is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{

t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
for(i=0;i<n;i++)
printf("%d\n",a[i]);break;
default: printf("Wrong choice entered");break;
}
return 0;
}

/* OUTPUT
Enter the limit of the array: 5
Enter the numbers of the array:
3
2
1
4
5
1.SORT BY SELECTION SORT TECHNIQUE
2.SORT BY BUBBLE SORT TECHNIQUE
Enter your choice: 1
Sorted array:
1
2
3
4
5
Enter the limit of the array: 5
Enter the numbers of the array:
3
2
1
4
5
1.SORT BY SELECTION SORT TECHNIQUE
2.SORT BY BUBBLE SORT TECHNIQUE
Enter your choice: 2
The sorted array is:
1
2
3
4
5
*/

Pgm 16 SAJESH S B
8/2/11 ROLL NO: 46

AIM:/*To write a pgm to enter data into a two dimensional array(matrix),


after accepting the array limit from the user.Print the entered data in a
matrix form*/

#include<stdio.h>
int main()
{
int a[10][10],r,c,i,j;
printf("Enter the number of rows and columns:\n");
scanf("%d %d",&r,&c);
printf("Enter the elements of the matrix:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
}
printf("The resulting matrix is:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d",a[i][j]);
printf("\t");
}
printf("\n");
}
return 0;
}
/*OUTPUT

Enter the number of rows and columns:


3
4
Enter the elements of the matrix:
14
2
67
4
45
8
7
89
24
56
67
78
The resulting matrix is:
14 2 67 4
45 8 7 89
24 56 67 78

*/
Pgm 19 SAJESH S B
15/3/11 ROLL NO: 46

AIM:/*To input a string and reverse it without using library functions*/

#include<stdio.h>
int main()
{
int i,len=0,j;
char a[20],b[20];
printf("Enter the string:\n");
scanf("%[^\n]",a);
for(i=0;a[i]!='\0';i++)
{ len++;}
b[len]='\0';
for(i=0,j=len-1;a[i]!='\0';i++,j--)
{
b[j]=a[i];
}
printf("The reverse of string:%s",b);
return 0;
}

/*OUTPUT

Enter the string:


DIFFICULT
The reverse of string:TLUCIFFID

*/
Pgm 20 SAJESH S B
15/3/11 ROLL NO: 46

AIM:/*WAP to input 2 strings and compare them and check


a)if they are the same length
b)If they are same,should be case sensitive */

#include<stdio.h>
#include<string.h>
int main()
{
int len1=0,len2=0;
char a[20];
char b[20];
printf("Enter the strings:\n");
scanf("%s\n",a);
scanf("%s\n",b);
len1=strlen(a);
len2=strlen(b);
if(len1==len2)
{
printf("Both strings have same length\n");
int x=strcmp(a,b);
if(x==0)
{
printf("They are same\n");
}
else
printf("They are different words of same length\n");
}
else
printf("Not of the same length\n");
return 0;
}

/*OUTPUT

Enter the strings:


SAJESH
rohith
Both strings have same length
They are different words of same length

*/

Pgm 21 SAJESH S B
15/3/11 ROLL NO: 46

AIM:/*Write a program to check if a string is palindrome*/


#include<stdio.h>
int main()
{
char a[20];
int i,j,len=0,count=0;
printf("Enter the string:\n");
scanf("%[^\n]",a);
for(i=0;a[i]!='\0';i++)
len++;
for(i=0,j=len-1;a[i]!='\0';i++,j--)
{
if(a[i]!=a[j])
{
printf("The string is not palindrome");
return 0;
}
else
count++;
}
if(count==len)
printf("The string is palindrome");
return 0;
}

/*OUTPUT

Enter the string:


MALAYALAM
The string is palindrome

*/
Pgm 22 SAJESH S B
15/3/11 ROLL NO: 46

AIM:/*To enter a string and convert lower case letters to upper case and
vice versa*/

#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main()
{
char s1[20];
int i;
printf("Enter the string:");
scanf("%s",s1);
int l=strlen(s1);
for(i=0;i<l;i++)
{
if(islower(s1[i]))
s1[i]=toupper(s1[i]);
else
s1[i]=tolower(s1[i]);
}
puts(s1);
return 0;
}

/*OUTPUT

Enter the string:blaHK


BLAhk

*/
Pgm 23 SAJESH S B
22/3/11 ROLL NO: 46

AIM:/*Factorial using recursive function*/

#include<stdio.h>
int fact(int);
int main()
{
int n,p;
printf("Enter the number to find factorial of:");
scanf("%d",&n);
p=fact(n);
printf("Factorial of %d:%d",n,p);
}
int fact(int n)
{
if(n<2)
return 1;
else
return n*(fact(n-1));
}

/*OUTPUT

Enter the number to find factorial of:6


Factorial of 6:720

*/
Pgm 24 SAJESH S B
22/3/11 ROLL NO: 46

AIM:/*Program to check if a number is a magic number using recursive


function. ie(6=1+2+3)*/

#include<stdio.h>
int magic(int,int);
int sum=0;
int main()
{
int n;
printf("Enter number to check if magic number or not:");
scanf("%d",&n);
int i=1;
int mag=magic(n,i);
if(mag==n)
printf("%d is a magic number",mag);
else
printf("%d is not a magical number",n);
return 0;
}
int magic(int n,int p);
{
if(p<n)
{ if(n%p==0)
{ sum=sum+p;
return magic(n,p+1); }
else
return sum;
}
}

/*OUTPUT

Enter number to check if magic number or not:6


6 is a magic number

*/
Pgm SAJESH S B
22 . 3. 11 ROLL NO: 46

AIM:/*Sine, cosine and logarithmic series/*

#include<stdio.h>
int sine()
{
int n,i;
float x,y,sinx;
printf("enter the value and limit");
scanf("%f%d",&x,&n);
x=x*22/(180*7);
y=x;
sinx=x;
printf("sin(%0.3f)=%0.3f",x,sinx);
for(i=2;i<=n;i++)
{
y=y*x*x/((2*i-1)*(2*i-2));
if(i%2==0)
{
sinx=sinx-y;
printf("-");
}
else
{
sinx=sinx+y;
printf("+");
}
printf("(%0.3f^%d)/%d!",x,(2*i-1),(2*i-1));
}
printf("\n=%0.3f\n",sinx);
}
int cosine()
{
int n,i;
float x,y=1,cosx=1;
printf("enter the value and limit");
scanf("%f%d",&x,&n);
x=x*22/(180*7);
printf("cos(%0.3f)=1",x);
for(i=2;i<=n;i++)

{
y=y*x*x/((2*i-3)*(2*i-2));
if(i%2==0)
{
cosx=cosx-y;
printf("-");
}
else
{
cosx=cosx+y;
printf("+");
}
printf("(%0.3f^%d)/%d!",x,(2*i-2),(2*i-2));
}
printf("\n=%0.3f\n",cosx);
}
int logseries()
{
int i,n;
float x,y,log,z;
printf("enter value and limit");
scanf("%f %d",&x,&n);
z=x-1;
y=z;
log=z;
printf("log(%0.3f)=(%0.3f-1)",x,x);
for(i=2;i<=n;i++)
{
y=y*z*(i-1)/i;
if(i%2==0)
{
log=log-y;
printf("-");
}
else
{
log=log+y;
printf("-");
}
printf("(%0.3f-1)^%d/%d!",x,i,i);
}

printf("\n=%0.3f\n",log);
}

int main()
{
int ch;
printf("Type 1 for sine series, 2 for cosine series, 3 for log series \n");
scanf("%d",&ch);
switch(ch)
{
case 1: sine();break;
case 2: cosine();break;
case 3: logseries();break;
default: printf("invalid choice\n");break;
}
return 0;
}

/*OUTPUT-1

Type 1 for sine series, 2 for cosine series, 3 for log series
1
enter the value and limit90
5
sin(1.571)=1.571-(1.571^3)/3!+(1.571^5)/5!-(1.571^7)/7!+(1.571^9)/9!
=1.000

/*OUTPUT-2

Type 1 for sine series, 2 for cosine series, 3 for log series
2
enter the value and limit56
5
cos(0.978)=1-(0.978^2)/2!+(0.978^4)/4!-(0.978^6)/6!+(0.978^8)/8!
=0.559

/*

Pgm 26(a) SAJESH S B


22/3/11 ROLL NO: 46

AIM:/*WAP to a)read a file


b)write a file

#include<stdio.h>
int main()
{
FILE *p;
char c;
p=fopen("SAJESH.txt","w");
printf("Enter character:");
while((c=getchar())!='\n')
putc(c,p);
fclose(p);
p=fopen("SAJESH.txt","r");
printf("Entered string is \n");
while((c=fgetc(p))!=EOF)
{
printf("%c",c);
}
fclose(p);
return 0;
}

/*OUTPUT

Enter character:hello
Entered string is
hello

*/
Pgm 26(c) SAJESH S B
22/3/11 ROLL NO: 46

AIM:/*WAP to append a file*/

#include<stdio.h>
#include<ctype.h>
int main()
{
FILE *p;
char c;
p=fopen("SAJESH.txt","a");
printf("Enter string:");
while((c=getchar())!='\n')
putc(c,p);
fclose(p);
p=fopen("SAJESH.txt","r");
printf("Entered string is \n");
while((c=fgetc(p))!=EOF)
{
printf("%c",c);
}
fclose(p);
return 0;
}

/*OUTPUT

Enter string:HELLO
Entered string is
helloHELLO

*/
Pgm 26(d) SAJESH S B
22/3/11 ROLL NO: 46

AIM:.To copy two files

#include<stdio.h>
int main()
{
FILE *p;
FILE *q;
char c,d;
p=fopen("SAJESH.txt","r");
q=fopen("point.txt","w");
printf("Copying:");
while((c=fgetc(p))!=EOF)
{
putc(c,q);
}
fclose(p);
fclose(q);
p=fopen("point.txt","r");
printf("The entered string is \n");
while((c=fgetc(p))!=EOF)
{
printf("%c",c);
}
fclose(p);
return 0;
}

/*OUTPUT

Copying:The entered string is


helloHELLO

*/

Pgm 16 SAJESH S B
22/03/11 Roll No:46

AIM: Matrix menu


#include<stdio.h>
#include<math.h>
float readmatrix(float a[25][25],float x,float y)
{
int i,j;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
scanf("%f",&a[i][j]);
}
}
return 0;
}
float writematrix(float a[25][25],float x,float y)
{
int i,j;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
printf("%0.1f\t",a[i][j]);
}
printf("\n");
}
return 0;
}
float addmatrix(float a[25][25],float b[25][25],float r1,float c1)
{
int i,j;
printf("Resultant matrix is \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%0.1f\t",a[i][j]+b[i][j]);
}
printf("\n");
}
return 0;
}

float multimatrix(float a[25][25],float b[25][25],float m,float q,float n)


{
float c[25][25];
int k,i,j;
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
}
}
printf("Resultant is \n");
writematrix(c,m,q);
return 0;
}
float detrm(float a[25][25],float k)
{
float s=1,det,b[25][25];
int i,j,m,n,c;
if(k==1)
{
return a[0][0];
}
else
{
det=0;
for(c=0;c<k;c++)
{
m=0;
n=0;
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
b[i][j]=0;
if(i!=0 && j!=c)
{
b[m][n]=a[i][j];
if(n<(k-2))
{
n++;
}

else
{
n=0;
m++;
}
}
}
}
det+=s*(a[0][c]*detrm(b,k-1));
s*=-1;
}
}
return det;
}
void inverse(float num[25][25],float f)
{
float b[25][25],fac[25][25],ft[25][25];
int p,q,m,n,i,j,detr;
detr=detrm(num,f);
for(p=0;p<f;p++)
{
for(q=0;q<f;q++)
{
m=0;
n=0;
for(i=0;i<f;i++)
{
for(j=0;j<f;j++)
{
b[i][j]=0;
if(i!=p && j!=q)
{
b[m][n]=num[i][j];
if(n<(f-2))
{
n++;
}
else
{
n=0;
m++;
}
}
}
}

fac[p][q]=pow(-1,p+q)*detrm(b,f-1);
ft[q][p]=fac[p][q];
ft[q][p]/=detr;
}
}
printf("Inverse of matrix is \n");
writematrix(ft,f,f);
}

int main()
{
float a[25][25],b[25][25],k,d,r1,c1,m,n,p,q;
int i,j,ch;
printf("1.Add 2.Multiply 3.Determinant 4.Inverse ?\n");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("Enter rows and columns of A and B matrix\n");
scanf("%f%f",&r1,&c1);
printf("Enter elemnts of A\n");
readmatrix(a,r1,c1);
printf("Enter B\n");
readmatrix(b,r1,c1);
addmatrix(a,b,r1,c1);
break;

case 2: printf("Enter rows and columns of A\n");


scanf("%f%f",&m,&n);
printf("Enter rows and columns aof B\n");
scanf("%f%f",&p,&q);
if(n==p)
{
printf("Enter matrix A\n");
readmatrix(a,m,n);
printf("Enter matrix B\n");
readmatrix(b,p,q);
multimatrix(a,b,m,q,n);
}
else
{
printf("Matrices not multipliable\n");
}
break;

case 3: printf("Enter order\n");


scanf("%f",&k);
printf("Enter elements\n");
readmatrix(a,k,k);
d=detrm(a,k);
printf("Determinant is %0.2f\n",d);
break;

case 4: printf("Enter order of matrix\n");


scanf("%f",&k);
printf("Enter elements\n");
readmatrix(a,k,k);
d=detrm(a,k);
if(d!=0)
{
inverse(a,k);
}
else
{
printf("Not inversible\n");
}
break;
}
return 0;
}
/*OUTPUT

1.Add 2.Multiply 3.Determinant 4.Inverse ?


1
Enter rows and columns of A and B matrix
22
Enter elemnts of A
1234
Enter B
1234
Resultant matrix is
2.0 4.0
6.0 8.0

/*

Pgm 18 SAJESH S B
19/3/11 ROLL NO:46

Aim: WAP to enter string and perform the following using structure
a)Find length b)Copy one string to other
c)Reverse String d) concatenate

#include<stdio.h>
#include<string.h>
struct str
{
char s1[20],s2[20];
int len;
}
int main()
{
struct str st;
int i,ch,j;
printf("Enter choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("Read string");
scanf(" %[^\n]",st.s1);
st.len=strlen(st.s1);
printf("\n The length of string is %d ",st.len);
break;
case 2:printf("Read string");
scanf(" %[^\n]",st.s1);
st.len=strlen(st.s1);
st.s2[st.len]='\0';
for(i=0,j=st.len-1;st.s1[i]!='\0';i++,j--)
{
st.s2[j]=st.s1[i];
}
printf("The reversed string is %s", st.s2);
break;
case 3:printf("Read string");
scanf(" %[^\n]",st.s1);
strcpy(st.s2,st.s1);
printf("The string is %s", st.s2);
case 4:printf("Read string1");
scanf(" %[^\n]",st.s1);
printf("Read string2");
scanf(" %[^\n]",st.s2);

strcat(st.s1,st.s2);
printf("The string is %s", st.s1);
break;
//default :
}
return 0;
}

/*OUTPUT

Enter choice(1-4)
1
Read string Hello

The length of string is 5

/*

S-ar putea să vă placă și