59. C program to reverse a single string without using 'strrev()' library function.
#include <stdio.h>
int main()
{
int n;
printf("enter the length of the string: ");
scanf("%d", &n);
char str[n];
printf("enter the string\n");
for(int j=0; j<=n; j++){
scanf("%c", &str[j]);
}
for(int i =n; i>=0; --i){
printf("%c", str[i]);
}
return 0;
}
#include <stdio.h>
int main()
{
int n;
printf("enter the length of the string: ");
scanf("%d", &n);
char str[n];
printf("enter the string\n");
for(int j=0; j<=n; j++){
scanf("%c", &str[j]);
}
for(int i =n; i>=0; --i){
printf("%c", str[i]);
}
return 0;
}
60. C program to find roots of quadratic equation.
#include <stdio.h>
#include <math.h>
int main(){
int a,b,c;
printf("enter the value of ab and c: ");
scanf("%d %d %d",&a, &b, &c);
float r1, r2;
float s = (b*b) - 4 * a * c;
if(s>0){
printf("roots are real:\n");
r1 = ((-b + sqrt(s)) / (2*a));
r2 = ((-b - sqrt(s)) / (2*a));
printf("(%.f, %.f)", r1, r2);
}
else{
printf("roots are imaginary");
r1 = -b / 2*a;
r2 = sqrt(s) / 2*a;
printf("(%.f+%.fi), (%.f+%.fi)",r1, r2, r1, r2);
}
return 0;
}
#include <stdio.h>
#include <math.h>
int main(){
int a,b,c;
printf("enter the value of ab and c: ");
scanf("%d %d %d",&a, &b, &c);
float r1, r2;
float s = (b*b) - 4 * a * c;
if(s>0){
printf("roots are real:\n");
r1 = ((-b + sqrt(s)) / (2*a));
r2 = ((-b - sqrt(s)) / (2*a));
printf("(%.f, %.f)", r1, r2);
}
else{
printf("roots are imaginary");
r1 = -b / 2*a;
r2 = sqrt(s) / 2*a;
printf("(%.f+%.fi), (%.f+%.fi)",r1, r2, r1, r2);
}
return 0;
}
|Quiz. #8|
What is the output?
#include <stdio.h> int main() { printf ("%d & %d", (36 & 28), (36 | 28)); return 0; }
What is the output?
#include <stdio.h> int main() { printf ("%d & %d", (36 & 28), (36 | 28)); return 0; }
Final Results
13%
36 28
16%
36 & 28
29%
4 & 60
42%
Error!!
#Explanation |Quiz. #8|
First of all, for both operations we have to convert these numbers in the of 8 bits(binary form) then apply to operations of '&' and '|' they are:
> & Will return 1 when both conditions are true i.e 1, otherwise it will return false i.e 0.
> | Will return 1 when any one condition is true I.e 1, otherwise it'll return false I.e 0
____________________________
(2^n..........32 16 8 4 2 1)
36 & 28:
36 -> 0 0 1 0 0 1 0 0
28 -> 0 0 0 1 1 1 0 0
______________
0 0 0 0 0 1 0 0 -> 4 ans.
36 | 28:
36 -> 0 0 1 0 0 1 0 0
28 -> 0 0 0 1 1 1 0 0
______________
0 0 1 1 1 1 0 0 -> 60 ans.
Hope you all understood.
Happy coding :)
First of all, for both operations we have to convert these numbers in the of 8 bits(binary form) then apply to operations of '&' and '|' they are:
> & Will return 1 when both conditions are true i.e 1, otherwise it will return false i.e 0.
> | Will return 1 when any one condition is true I.e 1, otherwise it'll return false I.e 0
____________________________
(2^n..........32 16 8 4 2 1)
36 & 28:
36 -> 0 0 1 0 0 1 0 0
28 -> 0 0 0 1 1 1 0 0
______________
0 0 0 0 0 1 0 0 -> 4 ans.
36 | 28:
36 -> 0 0 1 0 0 1 0 0
28 -> 0 0 0 1 1 1 0 0
______________
0 0 1 1 1 1 0 0 -> 60 ans.
Hope you all understood.
Happy coding :)
61. C program to find number of characters and number of spaces in a given string.
#include <stdio.h>
int main()
{
char str[]="do not do everything for something, just do something you will achieve everything\n";
printf("%s\n", str);
int countNum=0, countSp=0;
for(int a=0; a< strlen(str); a++)
{
if(str[a] != ' ') {
countNum++;
}
else{
countSp++;
}
}
printf("number of characters is: %d\nnumber of spaces is: %d\n",countNum, countSp);
return 0;
}
#include <stdio.h>
int main()
{
char str[]="do not do everything for something, just do something you will achieve everything\n";
printf("%s\n", str);
int countNum=0, countSp=0;
for(int a=0; a< strlen(str); a++)
{
if(str[a] != ' ') {
countNum++;
}
else{
countSp++;
}
}
printf("number of characters is: %d\nnumber of spaces is: %d\n",countNum, countSp);
return 0;
}
👍1
|Quiz. #9|
What is the output?
#include<stdio.h> int main(){ int ar[6]={4,1,9,8,5,9,5}; int *ptr1=ar; int *ptr2=&ar[4]; int res=ptr2 - ptr1; printf("%d",ar[res]); return 0; }
What is the output?
#include<stdio.h> int main(){ int ar[6]={4,1,9,8,5,9,5}; int *ptr1=ar; int *ptr2=&ar[4]; int res=ptr2 - ptr1; printf("%d",ar[res]); return 0; }
Anonymous Quiz
21%
1
21%
4
34%
5
23%
Error!
62. C program to compare first n characters of two given strings.
#include<stdio.h>
#include<string.h>
int main()
{
char str1[100], str2[100];
int n, cmp;
printf("enter first steing: ");
scanf("%[^\n]%*c", &str1);
printf("enter second string: ");
scanf("%[^\n]%*c", &str2);
printf("%s \n%s\n", str1, str2);
printf("enter number of characters: ");
scanf("%d", &n);
cmp=strncmp(str1, str2, n);
if(cmp==0)
printf("%d characters of these strings are equal",n);
else
printf("not equal");
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
char str1[100], str2[100];
int n, cmp;
printf("enter first steing: ");
scanf("%[^\n]%*c", &str1);
printf("enter second string: ");
scanf("%[^\n]%*c", &str2);
printf("%s \n%s\n", str1, str2);
printf("enter number of characters: ");
scanf("%d", &n);
cmp=strncmp(str1, str2, n);
if(cmp==0)
printf("%d characters of these strings are equal",n);
else
printf("not equal");
return 0;
}
63. C program to check how many characters are equal in two given strings. (Without using library function).
#include <stdio.h>
void cmpStr(char *str1, char *str2, int n){
int cmp=0;
for(int i=0; i<n; i++){
if(((str1[i] >=65 && str1[i]<=90) (str1[i] >= 97 && str1[i]<=122)) == ((str2[i] >=65 && str2[i]<=90) (str2[i] >= 97 && str2[i]<=122))){
if(str1[i] == str2[i]){
cmp=1;
}
else{
cmp=0;
}
}
if(cmp==1){
printf("character no. %d are equal\n", i);
}
else
printf("character no. %d are not equal\n", i);
}
}
int main()
{
char str1[100], str2[100];
int n;
printf("enter 1st srting: ");
scanf("%[^\n]%*c", &str1);
printf("enter 2nd srting: ");
scanf("%[^\n]%*c", &str2);
printf("enter number of character you ant to compare: ");
scanf("%d", &n);
cmpStr(str1, str2, n);
return 0;
}
#include <stdio.h>
void cmpStr(char *str1, char *str2, int n){
int cmp=0;
for(int i=0; i<n; i++){
if(((str1[i] >=65 && str1[i]<=90)
if(str1[i] == str2[i]){
cmp=1;
}
else{
cmp=0;
}
}
if(cmp==1){
printf("character no. %d are equal\n", i);
}
else
printf("character no. %d are not equal\n", i);
}
}
int main()
{
char str1[100], str2[100];
int n;
printf("enter 1st srting: ");
scanf("%[^\n]%*c", &str1);
printf("enter 2nd srting: ");
scanf("%[^\n]%*c", &str2);
printf("enter number of character you ant to compare: ");
scanf("%d", &n);
cmpStr(str1, str2, n);
return 0;
}
64. C program to compare n characters of two strings without case sensitivity.(without using library function)
#include <stdio.h>
void cmpStr(char *str1, char *str2, int n){
int cmp=0;
for(int i=0; i<n; i++){
if(((str1[i] >=65 && str1[i]<=90) (str1[i] >= 97 && str1[i]<=122)) == ((str2[i] >=65 && str2[i]<=90) (str2[i] >= 97 && str2[i]<=122))){
if(str1[i] == str2[i]){
cmp=1;
}
else{
cmp=0;
}
}
}
if(cmp==1){
printf("equal\n");
}
else
printf("not equal\n");
}
int main()
{
char str1[100], str2[100];
int n;
printf("enter 1st srting: ");
scanf("%[^\n]%*c", &str1);
printf("enter 2nd srting: ");
scanf("%[^\n]%*c", &str2);
printf("enter number of character you ant to compare: ");
scanf("%d", &n);
cmpStr(str1, str2, n);
return 0;
}
#include <stdio.h>
void cmpStr(char *str1, char *str2, int n){
int cmp=0;
for(int i=0; i<n; i++){
if(((str1[i] >=65 && str1[i]<=90)
if(str1[i] == str2[i]){
cmp=1;
}
else{
cmp=0;
}
}
}
if(cmp==1){
printf("equal\n");
}
else
printf("not equal\n");
}
int main()
{
char str1[100], str2[100];
int n;
printf("enter 1st srting: ");
scanf("%[^\n]%*c", &str1);
printf("enter 2nd srting: ");
scanf("%[^\n]%*c", &str2);
printf("enter number of character you ant to compare: ");
scanf("%d", &n);
cmpStr(str1, str2, n);
return 0;
}
65. C programme to convert lower case string into upper case string and upper case string into lower case string.
(Without using library functions)
#include <stdio.h>
void upperToLower(char *upper){
char lower[100];
for(int a=0; a<strlen(upper); a++)
{
if(upper[a] >=65 && upper[a]<= 90){
lower[a] = upper[a]+32;
printf("%c\n", lower[a]);
}
}
}
void lowerToUpper(char *lower){
char upper[100];
for(int a=0; a<strlen(lower); a++)
{
if(lower[a] >=97 && lower[a]<= 122){
upper[a] = lower[a]-32;
printf("%c\n", upper[a]);
}
}
}
int main()
{
char upper[100],lower[100];
printf("enter a upper case string: \n");
scanf("%s",&upper);
upperToLower(upper);
printf("enter a lower case string: \n");
scanf("%s",&lower);
lowerToUpper(lower);
return 0;
}
(Without using library functions)
#include <stdio.h>
void upperToLower(char *upper){
char lower[100];
for(int a=0; a<strlen(upper); a++)
{
if(upper[a] >=65 && upper[a]<= 90){
lower[a] = upper[a]+32;
printf("%c\n", lower[a]);
}
}
}
void lowerToUpper(char *lower){
char upper[100];
for(int a=0; a<strlen(lower); a++)
{
if(lower[a] >=97 && lower[a]<= 122){
upper[a] = lower[a]-32;
printf("%c\n", upper[a]);
}
}
}
int main()
{
char upper[100],lower[100];
printf("enter a upper case string: \n");
scanf("%s",&upper);
upperToLower(upper);
printf("enter a lower case string: \n");
scanf("%s",&lower);
lowerToUpper(lower);
return 0;
}
66. C programme to find minimum and maximum of two number without using CONDITIONAL STATEMENTS.
#include <stdio.h>
int retMax(int n1,int n2){
int ret = n1 ^ ((n1^n2) & -(n1<n2));
return ret;
}
int retMin(int n1, int n2){
int ret = n2 ^ ((n1^n2) & -(n1<n2));
return ret;
}
int main()
{
int x=5, y=3;
int min = retMin(x, y);
int max = retMax(x, y);
printf("minimum between %d and %d is: %d\n",x,y, min);
printf("maximum between %d and %d is: %d\n",x,y, max);
return 0;
}
#include <stdio.h>
int retMax(int n1,int n2){
int ret = n1 ^ ((n1^n2) & -(n1<n2));
return ret;
}
int retMin(int n1, int n2){
int ret = n2 ^ ((n1^n2) & -(n1<n2));
return ret;
}
int main()
{
int x=5, y=3;
int min = retMin(x, y);
int max = retMax(x, y);
printf("minimum between %d and %d is: %d\n",x,y, min);
printf("maximum between %d and %d is: %d\n",x,y, max);
return 0;
}
#DSA_Series
67. C programme to create Linked list using user defined function.
#include<stdio.h>
#include<stdlib.h>
typedef struct link{
int data;
struct link *next;
}link;
void show(link *ptr){
while(ptr != NULL){
printf("%d ", ptr->data);
ptr=ptr->next;
}
printf("\n");
}
link * insert(link *head, int data){
link *ptr = (link *) malloc(sizeof(link));
ptr->data=data;
ptr->next=head;
if(head==NULL){
head=ptr;
ptr->next=NULL;
return ptr;
}
else{
link *p;
p=head;
while(p->next != NULL){
p=p->next;
}
p->next=ptr;
ptr->next=NULL;
return head;
}
}
int main()
{
link *head=(link *) malloc(sizeof(link));
head = NULL;
int n;
printf("enter number of nodes: ");
scanf("%d",&n);
int ar[n];
printf("enter data: \n");
for(int a=0; a<n; a++){
printf("enter the value at index %d\n",a);
scanf("%d",&ar[a]);
}
for(int a=0; a<n; a++){
head = insert(head, ar[a]);
}
printf("your entered elements of linked list are : \n");
show(head);
return 0;
}
67. C programme to create Linked list using user defined function.
#include<stdio.h>
#include<stdlib.h>
typedef struct link{
int data;
struct link *next;
}link;
void show(link *ptr){
while(ptr != NULL){
printf("%d ", ptr->data);
ptr=ptr->next;
}
printf("\n");
}
link * insert(link *head, int data){
link *ptr = (link *) malloc(sizeof(link));
ptr->data=data;
ptr->next=head;
if(head==NULL){
head=ptr;
ptr->next=NULL;
return ptr;
}
else{
link *p;
p=head;
while(p->next != NULL){
p=p->next;
}
p->next=ptr;
ptr->next=NULL;
return head;
}
}
int main()
{
link *head=(link *) malloc(sizeof(link));
head = NULL;
int n;
printf("enter number of nodes: ");
scanf("%d",&n);
int ar[n];
printf("enter data: \n");
for(int a=0; a<n; a++){
printf("enter the value at index %d\n",a);
scanf("%d",&ar[a]);
}
for(int a=0; a<n; a++){
head = insert(head, ar[a]);
}
printf("your entered elements of linked list are : \n");
show(head);
return 0;
}
68. C programme to count how many characters, words, vowels, consonants, digits, spaces and special characters in a given string.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char str[500];
int len, num=0, sym=0, vowel=0, cons=0, wrd=0, total=0;
printf("enter a string: ");
scanf("%[^\n]%*c", &str);
len = strlen(str);
for(int i=0; i<len; i++){
if(str[i] >= 48 && str[i] <= 57)
num++;
else if(str[i] >= 33 && str[i] <=64 str[i]>=91 && str[i] <= 96)
sym++;
else if(str[i]==97 str[i]==101 str[i]==105 str[i]==111 str[i]==117)
vowel++;
else if(str[i]>=65 && str[i] <= 90 str[i] >= 97 && str[i] <= 122)
cons++;
else if(str[i] == ' ')
wrd++;
else
printf("didn't found\n'");
}
printf("numbers: %d\n", num);
printf("speceial symbol: %d\n", sym);
printf("vowel: %d\n", vowel);
printf("constent: %d\n", cons);
printf("words: %d\n", wrd);
printf("total number of characters: %d\n", len);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
char str[500];
int len, num=0, sym=0, vowel=0, cons=0, wrd=0, total=0;
printf("enter a string: ");
scanf("%[^\n]%*c", &str);
len = strlen(str);
for(int i=0; i<len; i++){
if(str[i] >= 48 && str[i] <= 57)
num++;
else if(str[i] >= 33 && str[i] <=64
sym++;
else if(str[i]==97
vowel++;
else if(str[i]>=65 && str[i] <= 90
cons++;
else if(str[i] == ' ')
wrd++;
else
printf("didn't found\n'");
}
printf("numbers: %d\n", num);
printf("speceial symbol: %d\n", sym);
printf("vowel: %d\n", vowel);
printf("constent: %d\n", cons);
printf("words: %d\n", wrd);
printf("total number of characters: %d\n", len);
return 0;
}
#DSA_Series
69. C programme for INSERT (at the beginning, at a given index, at the end), an element in a given LINKED LIST.
#include <stdio.h>
#include <stdlib.h>
typedef struct lList{
int data;
struct lList * next; /*a struct type pointer*/
}lList;
void likedListTraversal(lList *ptr){
while(ptr != NULL){
printf("%d \n",ptr->data);
ptr = ptr->next;
}
}
lList * lList_beginning_insertion(lList * head, int data){
lList *ptr = (lList*) malloc (sizeof(lList));
ptr->next = head;
ptr->data = data;
return ptr;
}
lList * lList_between_insertion(lList * head, int data, int index){
lList *ptr = (lList*) malloc (sizeof(lList));
lList *p = head;
int i=0;
while(i != index-1){
p = p->next;
i++;
}
ptr->data = data;
ptr->next = p->next;
p->next = ptr;
return head;
}
lList * lList_atEnd_insertion(lList * head, int data){
lList *ptr = (lList*) malloc (sizeof(lList));
lList *p =head;
ptr->data = data;
ptr->next = head;
while(p->next != NULL){
p = p->next;
}
p->next = ptr;
ptr->next =NULL;
return head;
}
int main()
{
lList * head;
lList * second;
lList * thired;
lList * fourth;
head = (lList*) malloc (sizeof(lList));
second = (lList*) malloc (sizeof(lList));
thired = (lList*) malloc (sizeof(lList));
fourth = (lList*) malloc (sizeof(lList));
head ->data = 7;
head ->next = thired;
second ->data = 9;
second ->next = thired;
thired ->data = 78;
thired ->next = fourth;
fourth ->data = 8;
fourth ->next = NULL;
printf("Before beginning insertion\n");
likedListTraversal(head);
printf("After beginning insertion\n");
head = lList_beginning_insertion(head,23);
likedListTraversal(head);
printf("Before between insertion\n");
likedListTraversal(head);
printf("After between insertion\n");
head = lList_between_insertion(head,89,2);
likedListTraversal(head);
printf("Before end insertion\n");
likedListTraversal(head);
printf("After end insertion\n");
head = lList_atEnd_insertion(head,900);
likedListTraversal(head);
return 0;
}
69. C programme for INSERT (at the beginning, at a given index, at the end), an element in a given LINKED LIST.
#include <stdio.h>
#include <stdlib.h>
typedef struct lList{
int data;
struct lList * next; /*a struct type pointer*/
}lList;
void likedListTraversal(lList *ptr){
while(ptr != NULL){
printf("%d \n",ptr->data);
ptr = ptr->next;
}
}
lList * lList_beginning_insertion(lList * head, int data){
lList *ptr = (lList*) malloc (sizeof(lList));
ptr->next = head;
ptr->data = data;
return ptr;
}
lList * lList_between_insertion(lList * head, int data, int index){
lList *ptr = (lList*) malloc (sizeof(lList));
lList *p = head;
int i=0;
while(i != index-1){
p = p->next;
i++;
}
ptr->data = data;
ptr->next = p->next;
p->next = ptr;
return head;
}
lList * lList_atEnd_insertion(lList * head, int data){
lList *ptr = (lList*) malloc (sizeof(lList));
lList *p =head;
ptr->data = data;
ptr->next = head;
while(p->next != NULL){
p = p->next;
}
p->next = ptr;
ptr->next =NULL;
return head;
}
int main()
{
lList * head;
lList * second;
lList * thired;
lList * fourth;
head = (lList*) malloc (sizeof(lList));
second = (lList*) malloc (sizeof(lList));
thired = (lList*) malloc (sizeof(lList));
fourth = (lList*) malloc (sizeof(lList));
head ->data = 7;
head ->next = thired;
second ->data = 9;
second ->next = thired;
thired ->data = 78;
thired ->next = fourth;
fourth ->data = 8;
fourth ->next = NULL;
printf("Before beginning insertion\n");
likedListTraversal(head);
printf("After beginning insertion\n");
head = lList_beginning_insertion(head,23);
likedListTraversal(head);
printf("Before between insertion\n");
likedListTraversal(head);
printf("After between insertion\n");
head = lList_between_insertion(head,89,2);
likedListTraversal(head);
printf("Before end insertion\n");
likedListTraversal(head);
printf("After end insertion\n");
head = lList_atEnd_insertion(head,900);
likedListTraversal(head);
return 0;
}
70. C programme to create an array DYNAMICALLY and searches a value whether the entered value is present in array or not.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n;
scanf ("%d",&n);
int *arr = (int *)malloc(n*sizeof(int));
printf("enter the values of the array: ");
int val;
for (int i=0; i<n; i++){
scanf("%d",&arr[i]);
}
printf ("enter the element to be searched: ");
scanf ("%d",&val);
for (int i=0; i<n; i++){
if(arr[i] == val){
printf ("entred element %d have been searched on index %d",val,i);
break ;
}
else{
printf ("element is not matching to index %d\n",i);
}
}
free(arr);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n;
scanf ("%d",&n);
int *arr = (int *)malloc(n*sizeof(int));
printf("enter the values of the array: ");
int val;
for (int i=0; i<n; i++){
scanf("%d",&arr[i]);
}
printf ("enter the element to be searched: ");
scanf ("%d",&val);
for (int i=0; i<n; i++){
if(arr[i] == val){
printf ("entred element %d have been searched on index %d",val,i);
break ;
}
else{
printf ("element is not matching to index %d\n",i);
}
}
free(arr);
return 0;
}
71. C program to sort an integer array in ascending order(using bubble sort).
#include <stdio.h>
void printArr(int *arr, int size){
for(int i=0; i<=size; i++){
printf("%d ", arr[i]);
}
printf("\n");
}
void sort(int *arr, int size){
int temp;
int isSorted=0;
for(int i=0; i<size-1; i++){
isSorted =1;
for(int j=0; j<=size-i-1; j++){
if(arr[j] > arr[j+1]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
isSorted =0;
}
}
if(isSorted){
return;
}
}
}
int main()
{
int arr[]={2,5,3,1,4,7,6};
int size =6;
printf("before sorting\n");
printArr(arr, size);
sort(arr, size);
printf("after sorting\n");
printArr(arr, size);
return 0;
}
#include <stdio.h>
void printArr(int *arr, int size){
for(int i=0; i<=size; i++){
printf("%d ", arr[i]);
}
printf("\n");
}
void sort(int *arr, int size){
int temp;
int isSorted=0;
for(int i=0; i<size-1; i++){
isSorted =1;
for(int j=0; j<=size-i-1; j++){
if(arr[j] > arr[j+1]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
isSorted =0;
}
}
if(isSorted){
return;
}
}
}
int main()
{
int arr[]={2,5,3,1,4,7,6};
int size =6;
printf("before sorting\n");
printArr(arr, size);
sort(arr, size);
printf("after sorting\n");
printArr(arr, size);
return 0;
}
72. C programme to convert decimal number to hexadecimal, using recursion.
#include <stdio.h>
#include <math.h>
void con(int n){
int rem, q,p, j=1;
p=n;
int ar[100];
if(n==0)
return;
else{
rem = p % 16;
if(rem < 10)
rem += 48;
else
rem += 55;
ar[j++] = rem;
q = p /16;
con(q);
for(int i=j-1; i>0; i--)
printf("%c", ar[i]);
}
}
int main()
{
char ar[100];
int rem;
int hex=1;
int n;
printf("enter a positive number: ");
scanf("%d", &n);
con(n);
return 0;
}
#include <stdio.h>
#include <math.h>
void con(int n){
int rem, q,p, j=1;
p=n;
int ar[100];
if(n==0)
return;
else{
rem = p % 16;
if(rem < 10)
rem += 48;
else
rem += 55;
ar[j++] = rem;
q = p /16;
con(q);
for(int i=j-1; i>0; i--)
printf("%c", ar[i]);
}
}
int main()
{
char ar[100];
int rem;
int hex=1;
int n;
printf("enter a positive number: ");
scanf("%d", &n);
con(n);
return 0;
}
73. C programme to check whether a matrices is symmetric matric or not.
#include <stdio.h>
int main()
{
int m, n, i, j;
printf("enter thr value of rows: ");
scanf("%d", &m);
printf("enter the value of columns: ");
scanf("%d", &n);
char mat[m][n];
char sym[m][n];
printf("enter the value of the matrices:\n");
for(i=0; i<m; i++){
for(j=0; j<n; j++){
scanf("%d", &mat[i][j]);
}
}
for(i=0; i<m; i++){
for(j=0; j<n; j++){
sym[j][i] = mat[i][j];
}
}
if(m==n){
for(i=0; i<m; i++){
for(j=0; j<m; j++){
if(mat[i][j] != sym[i][j]){
break;
}
}
if(j != m){
break;
}
}
}
if(i==m){
printf("matices is symmetric!");
}
else{
printf("matrices is not symmetric!");
}
return 0;
}
#include <stdio.h>
int main()
{
int m, n, i, j;
printf("enter thr value of rows: ");
scanf("%d", &m);
printf("enter the value of columns: ");
scanf("%d", &n);
char mat[m][n];
char sym[m][n];
printf("enter the value of the matrices:\n");
for(i=0; i<m; i++){
for(j=0; j<n; j++){
scanf("%d", &mat[i][j]);
}
}
for(i=0; i<m; i++){
for(j=0; j<n; j++){
sym[j][i] = mat[i][j];
}
}
if(m==n){
for(i=0; i<m; i++){
for(j=0; j<m; j++){
if(mat[i][j] != sym[i][j]){
break;
}
}
if(j != m){
break;
}
}
}
if(i==m){
printf("matices is symmetric!");
}
else{
printf("matrices is not symmetric!");
}
return 0;
}