Professional Documents
Culture Documents
#include<stdio.h>
#include<conio.h>
int main()
{
char Name[20],Bgroup[10];
int DOB[10];
printf("Enter the name\n");
scanf("\n%s",&Name);
printf("Enter the Date of Birth\n");
scanf("\n%s",&DOB);
printf("Enter the Blood Group\n");
scanf("\n%s",&Bgroup);
printf("The name is %s\n The Date of Birth is %s\n The Blood Group is %s\
n",Name,DOB,Bgroup);
return 0;
}
Q2. Write a program to display the ASCII
equivalent of a character.
#include<stdio.h>
#include<conio.h>
int main()
{
char ch;
int DOB[10];
printf("Enter the character\n");
scanf("\n%c",&ch);
printf("The ASCII value of the character is %d\n",ch);
return 0;
}
Q3. Write a program to give sum of two
numbers.
#include<stdio.h>
#include<conio.h>
int main()
{ int a,b;
printf("Enter the first number\n");
scanf("\n%d",&a);
printf("Enter the second number\n");
scanf("\n%d",&b);
int sum=a+b;
printf("\nThe sum of the two numbers is : %d",sum);
return 0; }
Q
6
.
Q9.
Write a program to calculate the average of
five numbers using function with argument
and without return value.
#include<stdio.h>
#include<conio.h>
float avg(int a,int b,int c,int d,int e)
{ float average=0;
average=(a+b+c+d+e)/5;
return average; }
int main()
{ float a,b,c,d,e;
printf("Enter the First number\n");
scanf("\n%f",&a);
printf("Enter the Second number\n");
scanf("\n%f",&b);
printf("Enter the Third number\n");
scanf("\n%f",&c);
printf("Enter the Fourth number\n");
scanf("\n%f",&d);
printf("Enter the Fifth number\n");
scanf("\n%f",&e);
printf("\nThe average of five numbers is :%f",avg(a,b,c,d,e));
return 0; }
int main()
{ int n;
printf("Enter the number\n");
scanf("%d",&n);
printf("Factorial is :%d",fact(n));
return 0;
}
#include<stdio.h>
#include<conio.h>
int main()
{ int n;
printf("Enter the height\n");
scanf("%d\n",&n);
for(int i=1;i<=n;i++)
{ for(int j=1;j<=i;j++)
{ printf(" * ");
}
printf("\n");}
return 0;
}
Q16. Write a program to store the values
entered by the user in an array and then
displays the position of those elements in an
array.
#include<stdio.h>
int main()
{ int n;
printf("Enter the length of the arrray\n");
scanf("%d",&n);
int arr[n];
printf("Enter the elements of the array\n");
for(int i=0;i<n;i++)
{ scanf("%d\n",&arr[i]);
} for(int i=0;i<n;i++)
{ printf("Position of element %d is:%d\n",arr[i],i);
}
return 0; }
Q17. Write a Program to find the average of
elements entered by the user in an array.
#include<stdio.h>
int main()
{ int n;
printf("Enter the length of the arrray\n");
scanf("%d",&n);
int arr[n];
printf("Enter the elements of the array\n");
for(int i=0;i<n;i++)
{ scanf("%d\n",&arr[i]);
}
int sum=0;
for(int i=0;i<n;i++)
{ sum+=arr[i]; }
float avg=sum/n;
printf("The average of the elements of the array entyered by the user in an
array is :%f",avg);
return 0;
}
Q18. Write a menu driven program for
matrices to do the following operation
depending on whether the operation requires
one or two matrices
1. Addition of two matrices
4. Transpose of a matrix
int main()
{
printf("Choose your operation:\n1. Press 1 for Addition of two matrices\n2.
Press 2 for Subtraction of two matrices\n3. Press 3 for Finding upper and lower
triangular matrices\n4. Press 4 for Transpose of a matrix\n5. Press 5 for
Product of two matrices");
int ch;
scanf("%d",&ch);
switch(ch){
case 1: add();
break;
case 2: subtract();
break;
case 3: triangular();
break;
case 4: transpose();
break;
case 5: product();
break;
default: printf("Invalid choice");
}
return 0;
}
void add(){
int n1,m1,n2,m2;
printf("Enter the rows and columns of first matrix:\n");
scanf("%d",&n1);
scanf("%d",&m1);
int arr1[n1][m1];
printf("Enter the elements of first matrix:\n");
for(int i=0;i<n1;i++){
for(int j=0;j<m1;j++){
scanf("%d",&arr1[n1][m1]);
}
}
printf("Enter the rows and columns of second matrix:\n");
scanf("%d",&n2);
scanf("%d",&m2);
int arr2[n2][m2];
printf("Enter the elements of second matrix:\n");
for(int i=0;i<n2;i++){
for(int j=0;j<m2;j++){
scanf("%d",&arr2[n2][m2]);
}
}
if(n1!=n2 || m1!=m2){
printf("Enter the same dimensions of both matrices");
return;
}
else{
int ad[n1][m1];
for(int i=0;i<n1;i++){
for(int j=0;j<m1;j++){
ad[i][j]=arr1[i][j]+arr2[i][j];
}
}
for(int i=0;i<n1;i++){
for(int j=0;j<m1;j++){
printf("%d",ad[i][j]);
}
printf("\n");
}
}
}
void subtract(){
int n1,m1,n2,m2;
printf("Enter the rows and columns of first matrix:\n");
scanf("%d",&n1);
scanf("%d",&m1);
int arr1[n1][m1];
printf("Enter the elements of first matrix:\n");
for(int i=0;i<n1;i++){
for(int j=0;j<m1;j++){
scanf("%d",&arr1[n1][m1]);
}
}
printf("Enter the rows and columns of second matrix:\n");
scanf("%d",&n2);
scanf("%d",&m2);
int arr2[n2][m2];
printf("Enter the elements of second matrix:\n");
for(int i=0;i<n2;i++){
for(int j=0;j<m2;j++){
scanf("%d",&arr2[n2][m2]);
}
}
if(n1!=n2 || m1!=m2){
printf("Enter the same dimensions of both matrices");
return;
}
else{
int res[n1][m1];
for(int i=0;i<n1;i++){
for(int j=0;j<m1;j++){
res[i][j]=arr1[i][j]-arr2[i][j];
}
}
for(int i=0;i<n1;i++){
for(int j=0;j<m1;j++){
printf("%d",res[i][j]);
}
printf("\n");
}
}
return;
}
void triangular(){
int n,m,cnt1=0,cnt2=0;
printf("Enter the rows and columns of matrix:\n");
scanf("%d %d",&n,&m);
int arr[n][m];
printf("Enter the elments:\n");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
scanf("%d",&arr[i][j]);
}
}
if(n!=m){
printf("Upper or lower triangular matrix not possible");
return;
}
else{
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(i>j){
if(arr[i][j]==0){
cnt1=1;
}
else{
cnt1=0;
}
}
else if(j>i){
if(arr[i][j]==0){
cnt2=1;
}
else{
cnt2=0;
}
}
}
}
if(cnt1==1){
printf("Upper triangular matrix");
}
if(cnt2==1){
printf("Lower triangular matrix");
}
if(cnt1==0 && cnt2==0){
printf("Neither upper nor lower triangular matrix");
}
}
}
void transpose(){
int n,m;
printf("Enter the number of rows and columns:\n");
scanf("%d %d",&n,&m);
int arr[n][m];
printf("Enter the elements of matrix:\n");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
scanf("%d",&arr[i][j]);
}
}
for(int i=0;i<n;i++){
for(int j=i;j<m;j++){
int temp=arr[i][j];
arr[i][j]=arr[j][i];
arr[j][i]=temp;
}
}
printf("Transpose of matrix is:\n");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
printf("%d",arr[i][j]);
}
printf("\n");
}
}
void product(){
int n1,m1,n2,m2;
printf("Enter the rows and columns of first matrix:\n");
scanf("%d",&n1);
scanf("%d",&m2);
int arr1[n1][m1];
printf("Enter the elements of first matrix:\n");
for(int i=0;i<n1;i++){
for(int j=0;j<m1;j++){
scanf("%d",&arr1[n1][m1]);
}
}
printf("Enter the rows and columns of second matrix:\n");
scanf("%d",&n2);
scanf("%d",&m2);
int arr2[n2][m2];
printf("Enter the elements of second matrix:\n");
for(int i=0;i<n2;i++){
for(int j=0;j<m2;j++){
scanf("%d",&arr2[n2][m2]);
}
}
int res[n1][m2];
printf("Result matrix is \n");
for (int i = 0; i < n1; i++) {
for (int j = 0; j < m2; j++){
for(int k=0;k<m1;k++){
res[i][j]+=arr1[i][k]+arr2[k][j];
}
}
}
for(int i=0;i<n1;i++){
for(int j=0;j<m2;j++){
printf("%d",res[i][j]);
}
printf("\n");
}
}
Q19. Write a program to find whether the
number entered by user is even or odd.
#include<stdio.h>
int main()
{ int n;
scanf("%d",&n);
if(n%2==0)
return 0;
int main()
{ int n,r,rev=0;
scanf("%d",&n);
int temp=n;
while(temp>0)
{ r=temp%10;
rev=rev*10+r;
temp=temp/10;
if(n==rev)
return 0;
int main()
{ int n;
scanf("%d",&n);
if(n%2==0)
return 0;
int main()
{ int n,r,rev=0;
scanf("%d",&n);
int temp=n;
while(temp>0)
{ r=temp%10;
rev=rev*10+r;
temp=temp/10;
if(n==rev)
return 0;
}
Q23. Write a program to swap two numbers
using pointers.
#include<stdio.h>
int main()
{ int x,y,*a,*b,temp;
scanf("%d%d\n",&x,&y);
a=&x;
b=&y;
temp=*b;
*b = *a;
*a = temp;
return 0;
}
Q24. Write a program to find whether the
character entered by user is a vowel using
switch statement.
/*Write a program to find whether the character entered by user is a vowel using switch
statement.*/
#include<stdio.h>
int main()
{ char ch;
scanf("%c\n",&ch);
switch(ch)
break;
break;
break;
break;
break;
break;
break;
break;
break;
break; }
return 0;