Array C
Array C
Array C
}
printf("\n");
}
getch();
}
2. Write a C program that reads two numbers and swap their content.
#include <stdio.h>
#include<conio.h>
void main()
{
int x, y, t;
clrscr();
printf("Enter first number:\n");
scanf("%d", &x);
printf("Enter second number:\n");
scanf("%d%”&y);
printf("Before Swapping\nFirst no. = %d\nSecond no.%d\n", x, y);
t = x;
x = y;
y = t;
printf("After Swapping\nFirst no. = %d\nSecond no. = %d\n", x, y);
getch();
}
3. Write a C program to input two numbers and swap without using third
variable.
#include <stdio.h>
#include<conio.h>
void main()
{
int a, b;
clrscr();
printf("Enter first number:\n");
scanf("%d", &a);
printf("Enter second number:\n");
scanf("%d”,&b);
a=a+b;
b=a-b;
a=a-b;
getch();
}
4. Write a C program to read an array of n integers and find the largest
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],i,n,large,small;
printf("How many elements:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the numbers:");
scanf("%d",&a[i]);
}
large=small=a[0]; // means large=a[0]; and small=a[0];
for(i=1;i<n;i++)
if(a[i]>large)
large=a[i];
if(a[i]<small)
small=a[i];
second is the result upon a true comparison, and the third is the result
an if-else statement.
#include<conio.h>
void main()
int a[2][3],b[3][2],prod[2][2];
int i,j,k;
clrscr();
for(i=0;i<2;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
for(i=0;i<3;i++)
for(j=0;j<2;j++)
scanf("%d",&b[i][j]);
}
for(i=0;i<2;i++)
for(j=0;j<2;j++)
prod[i][j]=0;
for(k=0;k<3;k++)
prod[i][j]=prod[i][j]+a[i][k]*b[k][j];
for(i=0;i<2;i++)
for(j=0;j<2;j++)
printf("%d\t",prod[i][j]);
printf("\n");
getch();