Professional Documents
Culture Documents
Ass 04
Ass 04
Ass 04
Assignment 04
// Main function
int main()
int arr1[100], n, ctr = 0; // Declare an array to store integer values, n for array size, and ctr for
counting duplicates
// Prompt the user to input the number of elements to be stored in the array
printf("------------------------------------------\n");
scanf("%d", &n);
if (i != j)
Jyotirmay SINGH PARIHAR- 23H027
{ if (arr1[i] == arr1[j])
{ ctr++;
if (ctr == 0)
printf("\n\n");
}
Output:Print all unique elements of an array:
------------------------------------------
Input the number of elements to be stored in the array: 4
Input 4 elements in the array :
element - 0 : 3
element - 1 : 2
element - 2 : 2
element - 3 : 5
void main() {
int arr1[50], i, pos, n;
int main() {
// Declare matrices and variables
int arr1[50][50], brr1[50][50], crr1[50][50], i, j, k, r1, c1, r2, c2, sum = 0;
} else {
// Input elements in the first matrix
printf("Input elements in the first matrix:\n");
for (i = 0; i < r1; i++) {
for (j = 0; j < c1; j++) {
printf("element - [%d],[%d] : ", i, j);
scanf("%d", &arr1[i][j]);
}
}
printf("%d\t", brr1[i][j]);
}
// Matrix multiplication
for (i = 0; i < r1; i++) { // Row of first matrix
for (j = 0; j < c2; j++) { // Column of second matrix
sum = 0;
for (k = 0; k < c1; k++)
sum = sum + arr1[i][k] * brr1[k][j];
crr1[i][j] = sum;
}
}
----------------------------------
1 2
3 4
The Second matrix is :
5 6
7 8
The multiplication of two matrices is :
19 22
43 50
Question4: Write a program in C to find transpose of a given matrix, Input the rows and columns of
the, matrix : 3 3
Answer4: input:
#include <stdio.h>
int main() {
int a[10][10], transpose[10][10], r, c;
printf("Enter rows and columns: ");
scanf("%d %d", &r, &c);
// In a square matrix, if all the main diagonal elements are 1's and
// all the remaining elements are 0's, it is called an Identity Matrix.
int main() {
int arr1[10][10];
int r1, c1;
int i, j, yn = 1;
return 0;
}
#include <stdlib.h>
void main()
{
char str[100]; /* Declares a string of size 100 */
int l,i;
m o c . e c r u o s e r 3 w
Question7: Write a program in C to count the total number of alphabets, digits and special characters
in a string.
TestData :
Input the string : Welcome to w3resource.com
Expected Output :
Number of Alphabets in the string is : 21
Number of Digits in the string is : 1
Number of Special characters in the string is : 4
Answer7:
Input: #include <stdio.h>
#include <string.h>
Jyotirmay SINGH PARIHAR- 23H027
#include <stdlib.h>
void main()
{
char str[str_size];
int alp, digit, splch, i;
alp = digit = splch = i = 0;
while(str[i]!='\0')
{
if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
{
alp++;
}
else if(str[i]>='0' && str[i]<='9')
{
digit++;
}
else
{
splch++;
Jyotirmay SINGH PARIHAR- 23H027
i++;
}
#include <stdio.h>
input:
#include <string.h>
int main() {
char string1[20];
int i, length;
int flag = 0;
return 0;
}
Question9: Write a program to develop your own functions for performing following operations on
strings. i. Copying one string to another.
Answer9:
i input:
#include <stdio.h>
int main() {
char s1[1000];
char s2[1000];
printf("Enter any string: ");
gets(s1);
int i;
for(i=0;s1[i]!='\0';i++) {
s2[i]=s1[i];
}
s2[i]='\0';
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;
}
Question10: Write a program to check whether the entered number is circular prime, partially circular
prime or not a circular prime. If the 5 digit number is taken as input from the keyboard and check
every possible circular rotation of input number is prime or not.
If all the rotation of a number is prime then say entered is circular prime.
If half of the rotation of a number is prime not all then say entered number is partially prime.
If no rotation is prime and the only number is prime then say entered number is not a circular prime
Answer10:
input: // Program to check if a number is circular
// prime or not.
#include <iostream>
#include <cmath>
using namespace std;
return true;
}
int num = N;
while (isPrime(num)) {
return false;
}
// Driver Program
int main()
{
int N = 1193;
if (checkCircular(N))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}