C Program Assignment
C Program Assignment
C Program Assignment
Contents
1
1. Write a program to find the multiplication of two matrices.
Program
#include <stdio.h>
int main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
if (n != p)
printf("Matrices with entered orders can't be multiplied with each other.\n");
else
{
printf("Enter the elements of second matrix\n");
multiply[c][d] = sum;
sum = 0;
}
}
2
for (d = 0; d < q; d++)
printf("%d\t", multiply[c][d]);
printf("\n");
}
}
return 0;
}
Output
Program
#include <stdio.h>
int main()
{
char ch;
printf("Enter a character\n");
scanf("%c", &ch);
3
return 0;
}
Output
Program
#include <stdio.h>
int main()
{
int year;
if ( year%400 == 0)
printf("%d is a leap year.\n", year);
else if ( year%100 == 0)
printf("%d is not a leap year.\n", year);
else if ( year%4 == 0 )
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year);
return 0;
}
Output
4
4. Write a program to find factorial using for loop.
Program
#include <stdio.h>
int main()
{
int c, n, fact = 1;
return 0;
}
Output
Program
#include <stdio.h>
int main() {
int a, b, x, y, t, gcd, lcm;
a = x;
b = y;
while (b != 0) {
t = b;
b = a % b;
a = t;
}
5
gcd = a;
lcm = (x*y)/gcd;
return 0;
}
Output
Program
#include <stdio.h>
int main()
{
int n, c, k;
if (k & 1)
printf("1");
else
printf("0");
}
printf("\n");
return 0;
}
Output
6
7. Write a program to swap two numbers.
Program
#include <stdio.h>
int main()
{
int x, y, temp;
temp = x;
x = y;
y = temp;
return 0;
}
Output
Program
#include <stdio.h>
int main()
{
int n, reverse = 0;
7
scanf("%d", &n);
while (n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
return 0;
}
Output
Program
#include <stdio.h>
int main()
{
int n, c, k, space = 1;
space = n - 1;
space--;
printf("\n");
}
8
space = 1;
space++;
printf("\n");
}
return 0;
}
Output
Program
#include<stdio.h>
int main()
{
int n, first = 0, second = 1, next, c;
9
printf("First %d terms of Fibonacci series are :-\n",n);
return 0;
}
Output
Program
#include <stdio.h>
int main()
{
int first, second, *p, *q, sum;
p = &first;
q = &second;
sum = *p + *q;
10
printf("Sum of entered numbers = %d\n",sum);
return 0;
}
Output
Program
#include <stdio.h>
int main()
{
int array[100], maximum, size, c, location = 1;
maximum = array[0];
11
Output
Program
#include <stdio.h>
int main()
{
int n, c, d, a[100], b[100];
return 0;
}
Output
12
14. Write a program to add two matrices.
Program
#include <stdio.h>
int main()
{
int m, n, c, d, first[10][10], second[10][10], sum[10][10];
return 0;
}
13
Output
Program
#include <stdio.h>
int main()
{
int m, n, c, d, matrix[10][10], transpose[10][10];
return 0;
}
14
Output
Program
#include <stdio.h>
#include <string.h>
int main()
{
char a[100];
int length;
length = strlen(a);
return 0;
}
Output
Program
#include <stdio.h>
int main()
15
{
char text[1000], blank[1000];
int c = 0, d = 0;
blank[d] = '\0';
return 0;
}
Output
Program
#include <stdio.h>
struct complex
{
16
int real, img;
};
int main()
{
struct complex a, b, c;
if ( c.img >= 0 )
printf("Sum of two complex numbers = %d + %di\n", c.real, c.img);
else
printf("Sum of two complex numbers = %d %di\n", c.real, c.img);
return 0;
}
Output
Program
#include <stdio.h>
#include <string.h>
17
#include <malloc.h>
int main()
{
char first[100], second[100], *temp;
printf("\nBefore Swapping\n");
printf("First string: %s\n",first);
printf("Second string: %s\n\n",second);
temp = (char*)malloc(100);
strcpy(temp,first);
strcpy(first,second);
strcpy(second,temp);
printf("After Swapping\n");
printf("First string: %s\n",first);
printf("Second string: %s\n",second);
return 0;
}
Output
18
20. Write a program to delete an element from an array.
Program
#include <stdio.h>
int main()
{
int array[100], position, c, n;
return 0;
}
Output
19
20