Page 8 of 12
1 6 7 8 9 10 12

Coding Questions

Coding Question 42

Write a program to find the transpose of a matrix. C C #include<stdio.h> int main(){int a[3][3],i,j,val,row,col,k; for(i=0;i<3;i++){for(j=0;j<3;j++){printf(“n Enter a number: “);scanf(“%d”,&a[i][j]); }} for(i=0;i<3;i++){ printf(“n”);for(j=0;j<3;j++){printf(“%dt”,a[i][j]); }} printf(“n Transpose Matrix: “);for(i=0;i<3;i++){ printf(“n”);for(j=0;j<3;j++){printf(“%dt”,a[j][i]); }} return 0;}

Coding Question 41

Write a C program which will take input in a 2D array and then take one integer as input and search it is available or not, if it is available display the row and column of the integer. C C #include<stdio.h> int main(){int a[3][3],i,j,val,row,col,k; for(i=0;i<3;i++){for(j=0;j<3;j++){printf(“n Enter a number: “);scanf(“%d”,&a[i][j]); }} for(i=0;i<3;i++){ printf(“n”);for(j=0;j<3;j++){printf(“%dt”,a[i][j]); }} printf(“n Enter …

Coding Question 41 Read More »

Coding Question 40

Write a program to create an array of n elements and then print maximum and minimum elements from that array. C C #include<stdio.h> int main(){int i,max,min,a[10]; for(i=0;i<10;i++){printf(“n Enter a Number: “);scanf(“%d”,&a[i]); }for(i=0;i<10;i++){printf(“n%d”,a[i]); } max=min=a[0]; for(i=0;i<10;i++){if(a[i]>max)max=a[i];if(a[i]<min)min=a[i];} printf(“n %d is max”,max);printf(“n %d is min”,min); return 0;}  

Coding Question 39

Write a C program to find the average of n numbers. C C #include<stdio.h> int main(){int num,i,count,sum=0;printf(“n How many nos. you want tio add? “);scanf(“%d”,&count); for(i=0;i<count;i++){printf(“n Enter a Number: “);scanf(“%d”,&num);sum=sum+num; } printf(“n Aveage= %.2f”, (float)sum/(float)count); return 0;}  

Coding Question 38

Write a program in C which prints the smallest divisor of an integer , for example smallest divisor of 77 is 7. C C #include<stdio.h> int main(){ int num,i;printf(“n Enter the number: “);scanf(“%d”,&num); for(i=2;i<=num;i++){if(num%i==0){printf(“n %d is the smallest divisor of %d”,i,num);break;}} return 0;}

Coding Question 37

Write a function to sort the characters of the string passed to it as argument. C C #include<stdio.h> int main(){char c[100],ch;int i,j; printf(“n Enter the String: “);gets(c); for(i=0;c[i]!=’′;i++){for(j=i+1;c[j]!=’′;j++){if(c[i]>c[j]){ch=c[i];c[i]=c[j];c[j]=ch;}} } printf(“n”);puts(c); return 0;}  

Coding Question 36

Write two C programs that calculates factorial of a number using recursion and iteration. C C #include<stdio.h> int fact(int i){ if(i==0)return 1; if(i==1)return 1; return (i*fact(i-1));} int main(){int i; printf(“n Enter a number: “);scanf(“%d”,&i);printf(“nFactorial of %d = %d “, i, fact(i)); return 0;}

Coding Question 35

Write a C-program to implement the Tower of Hanoi problem using recursion. C C #include <stdio.h>void towerfun(int, char, char, char);int main(){int n;printf(“Enter the number of disks : “);scanf(“%d”, &n);printf(“The sequence of moves involved in the Tower of Hanoi are :n”);towerfun(n, ‘A’, ‘C’, ‘B’); // A, B, C are towerreturn 0;} void towerfun(int n, char fr, …

Coding Question 35 Read More »

Coding Question 34

Write a program to check a number is special or not. (Special is a number which is  equal to the sum of factorial of each digit of the given number). C C #include<stdio.h> int fact(int n){int i,f=1; for(i=1;i<=n;i++)f=f*i;2 return f;} int main(){int num,sum=0,temp,r;printf(“n Enter a number: “);scanf(“%d”,&num); temp=num; while(num!=0){r=num%10;sum=sum+fact(r);num=num/10;} if(temp==sum)printf(“n %d is a special no.”,temp);elseprintf(“n …

Coding Question 34 Read More »