18. C program to find n power of a number.
#include <stdio.h>
int main()
{
int a, b, temp, res=1;
printf("Enter a numbers: ");
scanf("%d", &a);
printf("Enter power of %d: ",a);
scanf("%d",&b);
for(int i =1; i<=b; i++){
temp = a;
res = res * temp;
}
printf("result = %d", res);
return 0;
}
#include <stdio.h>
int main()
{
int a, b, temp, res=1;
printf("Enter a numbers: ");
scanf("%d", &a);
printf("Enter power of %d: ",a);
scanf("%d",&b);
for(int i =1; i<=b; i++){
temp = a;
res = res * temp;
}
printf("result = %d", res);
return 0;
}
20. C program to find multiplication of two matrices.
#include <stdio.h>
int main()
{
printf ("***matrices multiplication***\n");
int a[2][2], b[2][2], c[2][2];
int i, j;
printf("enterthe elements of 1st matric:\n");
for(i = 0;i< 2;i++){
for(j = 0;j< 2;j++)
scanf("%d",&a[i][j]);
}
printf("enter the elements of 2nd matric:\n");
for(i = 0;i< 2;i++){
for(j = 0;j< 2;j++)
scanf("%d",&b[i][j]);
}
printf ("resulted matric..\n");
for(i = 0;i< 2;i++){
for(j = 0;j< 2;j++){
c[i][j]=0;
for(int k=0; k<2; k++){
c[i][j] += a[i][k] * b[k][j];
}
printf ("%d ",c[i][j]);
}
printf ("\n");
}
return 0;
}
i
#include <stdio.h>
int main()
{
printf ("***matrices multiplication***\n");
int a[2][2], b[2][2], c[2][2];
int i, j;
printf("enterthe elements of 1st matric:\n");
for(i = 0;i< 2;i++){
for(j = 0;j< 2;j++)
scanf("%d",&a[i][j]);
}
printf("enter the elements of 2nd matric:\n");
for(i = 0;i< 2;i++){
for(j = 0;j< 2;j++)
scanf("%d",&b[i][j]);
}
printf ("resulted matric..\n");
for(i = 0;i< 2;i++){
for(j = 0;j< 2;j++){
c[i][j]=0;
for(int k=0; k<2; k++){
c[i][j] += a[i][k] * b[k][j];
}
printf ("%d ",c[i][j]);
}
printf ("\n");
}
return 0;
}
i
21. C program to swap two characters.
#include <stdio.h>
void character_swaping(char *a, char *b);
int main()
{
char ch1 = 's';
char ch2 = 'r';
printf("character before swaping:\nch1 = %c ch2 = %c\n",ch1, ch2);
character_swaping(&ch1, &ch2);
printf("character after swaping:\nch1 = %c ch2 = %c\n",ch1, ch2);
return 0;
}
void character_swaping(char *a, char *b){
char temp;
temp = *a;
*a = *b;
*b = temp;
}
#include <stdio.h>
void character_swaping(char *a, char *b);
int main()
{
char ch1 = 's';
char ch2 = 'r';
printf("character before swaping:\nch1 = %c ch2 = %c\n",ch1, ch2);
character_swaping(&ch1, &ch2);
printf("character after swaping:\nch1 = %c ch2 = %c\n",ch1, ch2);
return 0;
}
void character_swaping(char *a, char *b){
char temp;
temp = *a;
*a = *b;
*b = temp;
}
23. C program to convert numbers into roman digit's.
#include<stdio.h>
int rom(int, char);
int roman(int n){
int m = n/1000;
n = n % 1000;
rom(m,'m');
int d = n /500;
n = n % 500;
rom(d,'D');
int c = n /100;
n = n % 100;
rom(c,'c');
int l = n /50;
n = n % 50;
rom(l,'L');
int x = n /10;
n = n % 10;
rom(x,'x');
int v = n /5;
n = n % 5;
rom(v,'v');
int i = n /1;
n = n % 1;
rom(i,'i');
return 0;
}
int rom(int q,char h){
for(int i =0;i<q;i++){
printf ("%c",h);
}
return 0;
}
int main() {
int num;
scanf("%d",&num);
printf("Roman value of %d is: ", num);
roman(num);
return 0;
}
#include<stdio.h>
int rom(int, char);
int roman(int n){
int m = n/1000;
n = n % 1000;
rom(m,'m');
int d = n /500;
n = n % 500;
rom(d,'D');
int c = n /100;
n = n % 100;
rom(c,'c');
int l = n /50;
n = n % 50;
rom(l,'L');
int x = n /10;
n = n % 10;
rom(x,'x');
int v = n /5;
n = n % 5;
rom(v,'v');
int i = n /1;
n = n % 1;
rom(i,'i');
return 0;
}
int rom(int q,char h){
for(int i =0;i<q;i++){
printf ("%c",h);
}
return 0;
}
int main() {
int num;
scanf("%d",&num);
printf("Roman value of %d is: ", num);
roman(num);
return 0;
}
If you've any query or doubt about these programs , kindly DM me , I'll try to solve them.
Thank you..
Happy Coding :)
Thank you..
Happy Coding :)
25. C program to add two matrices.
#include <stdio.h>
int main()
{
printf ("***matrices addition***\n");
int a[2][2], b[2][2], c[2][2];
int i, j;
printf("enter the elements of 1st matric:\n");
for(i = 0;i< 2;i++){
for(j = 0;j< 2;j++)
scanf("%d",&a[i][j]);
}
printf("enter the elements of 2nd matric:\n");
for(i = 0;i< 2;i++){
for(j = 0;j< 2;j++)
scanf("%d",&b[i][j]);
}
printf ("resulted matric..\n");
for(i = 0;i< 2;i++){
for(j = 0;j< 2;j++){
c[i][j] = a[i][j] + b[i][j];
printf ("%d",c[i][j]);
}
printf ("\n");
}
return 0;
}
#include <stdio.h>
int main()
{
printf ("***matrices addition***\n");
int a[2][2], b[2][2], c[2][2];
int i, j;
printf("enter the elements of 1st matric:\n");
for(i = 0;i< 2;i++){
for(j = 0;j< 2;j++)
scanf("%d",&a[i][j]);
}
printf("enter the elements of 2nd matric:\n");
for(i = 0;i< 2;i++){
for(j = 0;j< 2;j++)
scanf("%d",&b[i][j]);
}
printf ("resulted matric..\n");
for(i = 0;i< 2;i++){
for(j = 0;j< 2;j++){
c[i][j] = a[i][j] + b[i][j];
printf ("%d",c[i][j]);
}
printf ("\n");
}
return 0;
}
26. C program to find individual digits without using if-else and switch case instructions.
#include <stdio.h>
char ind[][10] = {"zero","one","two","three","four","five", "six", "seven", "eight","nine"};
void find(int num){
int dg[10], count=0;
do{
dg[count] = num % 10;
num /= 10;
count++;
} while (num != 0);
for(int i = count -1; i >= 0; i--){
printf("%s ", ind[dg[i]]);
}
}
int main(){
int num;
printf ("enter a number: ");
scanf ("%d",&num);
find(num);
return 0;
}
#include <stdio.h>
char ind[][10] = {"zero","one","two","three","four","five", "six", "seven", "eight","nine"};
void find(int num){
int dg[10], count=0;
do{
dg[count] = num % 10;
num /= 10;
count++;
} while (num != 0);
for(int i = count -1; i >= 0; i--){
printf("%s ", ind[dg[i]]);
}
}
int main(){
int num;
printf ("enter a number: ");
scanf ("%d",&num);
find(num);
return 0;
}
Quiz.#1 what will be the output of this c program?
#include <stdio.h>
int main(){ // printf("1st");\ printf("2nd"); printf("3rd"); return 0; }
#include <stdio.h>
int main(){ // printf("1st");\ printf("2nd"); printf("3rd"); return 0; }
Anonymous Quiz
34%
1st 2nd 3rd
23%
2nd 3rd
18%
3rd
25%
Error!
#Explanation:
The correct answer is 3rd becoz , as you all know that '//' are used for give a comment, comment means compiler will skip these part of the code, and will execute next statement of the code, but if I write a comment , which will terminate with '\' symbol then compiler will skip the next line of the code and will execute the third line of the code and that's known as "Line splicing".
Hope you understood!
Happy coding :)
The correct answer is 3rd becoz , as you all know that '//' are used for give a comment, comment means compiler will skip these part of the code, and will execute next statement of the code, but if I write a comment , which will terminate with '\' symbol then compiler will skip the next line of the code and will execute the third line of the code and that's known as "Line splicing".
Hope you understood!
Happy coding :)
Quiz. #2 what will be the output of the following c code?
#include <stdio.h>
int main(){ char ch = 'a'; char ch2 = 'b'; int add; add = ch + ch2; printf("res = %d", add); return 0; } Note: ASCII value: a=97, b=98
#include <stdio.h>
int main(){ char ch = 'a'; char ch2 = 'b'; int add; add = ch + ch2; printf("res = %d", add); return 0; } Note: ASCII value: a=97, b=98
Anonymous Quiz
6%
198
16%
c
58%
195
19%
Error!
Quiz. #3 what will be the output?
#include <stdio.h>
int main(){ int val1=50; int val2=50; int sum= val1+val2; printf("result = %c", sum); return 0; }
#include <stdio.h>
int main(){ int val1=50; int val2=50; int sum= val1+val2; printf("result = %c", sum); return 0; }
Anonymous Quiz
42%
100
25%
d
3%
50
31%
Error!
29. C program to find whether a character is a upper case character or lower case character or special symbol or a number(by using switch case instructions).
#include <stdio.h>
int main(){
char ch;
int val =0;
printf("enter a character: ");
scanf("%c",&ch);
if(ch>= 97 && ch<= 122)
val = 1;
else if(ch>=65 && ch<90)
val = 2;
else if(ch>=33 && ch<= 64 || ch>=91 && ch<=96)
val = 3;
else if(ch >= 48 && ch<=57)
val = 4;
else
val = 0;
switch(val){
case 1:
printf("%c is a lower case alphabet",ch);
break;
case 2:
printf("%c is a upper case alphabet",ch);
break;
case 3:
printf("%c is a special symbol",ch);
break;
case 4:
printf("%c is a numerical digit",ch);
default:
printf("Another character");
}
return 0;
}
#include <stdio.h>
int main(){
char ch;
int val =0;
printf("enter a character: ");
scanf("%c",&ch);
if(ch>= 97 && ch<= 122)
val = 1;
else if(ch>=65 && ch<90)
val = 2;
else if(ch>=33 && ch<= 64 || ch>=91 && ch<=96)
val = 3;
else if(ch >= 48 && ch<=57)
val = 4;
else
val = 0;
switch(val){
case 1:
printf("%c is a lower case alphabet",ch);
break;
case 2:
printf("%c is a upper case alphabet",ch);
break;
case 3:
printf("%c is a special symbol",ch);
break;
case 4:
printf("%c is a numerical digit",ch);
default:
printf("Another character");
}
return 0;
}