C Programming
C Programming
#include<stdio.h>
int main()
{
int a,b,c;
printf("enter three integer:");
scanf("%d%d%d",&a,&b,&c);
if(a>=b && a>=c)
printf("%d is the largest integer",a);
else if(b>=a && b>=c)
printf("%d is the largest integer",b);
else
printf("%d is the largest integer",c);
return 0;
}
output:
enter three integer:21 24 23
24 is the largest integer
#include<stdio.h>
#include<string.h>
int main()
{// palindrome string
char str[100];
int i,len;
printf("enetr string ");
gets(str);
len=strlen(str);
for(i=0;i<len/2;i++)
{ if(str[i]!=str[len-i-1])
{
printf(" not palindrome");
break;
}
}
if(i==len/2)
printf(" palindrome");
return 0;
}
output:
enter string rahul
not palindrome
enter string malayalam
palindrome
5.write a c program to find the sum and average of n integers using a linear array.
#include<stdio.h>
int main()
{
int i,n,sum=0,num;
float avg;
avg = sum/(float)n;
return 0;
}
output:
Enter How many Number you want?
4
Enter elements one by one
10 12 13 14
Sum of 4 Numbers = 49
Average of 4 Numbers = 12.25
// main function
int main()
{
// matrix
int a[][3] = { {5,6,7}, {8,9,10}, {3,1,2} };
int b[][3] = { {1,2,3}, {4,5,6}, {7,8,9} };
int c[3][3];
// menu-driven
do
{
// menu to choose the operation
printf("\nChoose the matrix operation,\n");
printf("----------------------------\n");
printf("1. Addition\n");
printf("2. Multiplication\n");
printf("3. Transpose\n");
printf("4. Exit\n");
printf("----------------------------\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add(a, b, c);
printf("Sum of matrix: \n");
display(c);
break;
case 2:
multiply(a, b, c);
printf("Multiplication of matrix: \n");
display(c);
break;
case 3:
printf("Transpose of the first matrix: \n");
transpose(a, c);
display(c);
printf("Transpose of the second matrix: \n");
transpose(b, c);
display(c);
break;
case 4:
printf("Thank You.\n");
exit(0);
default:
printf("Invalid input.\n");
printf("Please enter the correct input.\n");
}
}while(1);
return 0;
}
output:
First Matrix:
5 6 7
8 9 10
3 1 2
Second Matrix:
1 2 3
4 5 6
7 8 9
}
output:factorial of nth term:5
factorial of nth term is 5=120
(b).reverse
#include<stdio.h>
int main()
{
// input 234....>432
int n,r;
printf("enter number:");
scanf("%d",&n);
while(n>0)
{
r=n%10;
printf("%d",r);
n=n/10;
}
return 0;
}
output:
enter number:123
321
(c).string matching
#include <stdio.h>
#include<string.h>
int main()
{
char str1[20]; // declaration of char array
char str2[20]; // declaration of char array
int value; // declaration of integer variable
printf("Enter the first string : ");
scanf("%s",str1);
printf("Enter the second string : ");
scanf("%s",str2);
// comparing both the strings using strcmp() function
value=strcmp(str1,str2);
if(value==0)
printf("strings are same");
else
printf("strings are not same");
return 0;
}
output:
Enter the first string : rahul
Enter the second string : kumar
strings are not same
}
int main()
{
int a,b;
printf("enter two no:");
scanf("%d%d",&a,&b);
swap(&a,&b);
printf("a=%d b=%d",a,b);
return 0;
}
output:
enter two no:1 2
p=2 q=1a=2 b=1