#include <stdio.h>
int main()
{
int n,count=0;
printf("Enter an integer: ");
scanf("%d", &n);
while(n!=0)
{
n/=10;
/* n=n/10 */
++count;
}
printf("Number of digits: %d",count);
}
Output
Enter an integer: 34523
Number of digits: 5
Output
Enter a string: This website is awesome.
Enter a frequency to find frequency: e
Frequency of e = 4
Output
Enter a string: p2'r"o@gram84iz./
Output String: programiz
Output 1
Enter a character: *
* is not an alphabet
Enter a character: K
K is an alphabet
char sentence[100];
7.
8.
9.
10.
11.
12.
13.
14.
sentence[i] = '\0';
15.
16.
count = i;
17.
18.
19.
20.
21.
ch = islower(sentence[i])? toupper(sentence[i]) :
22.
tolower(sentence[i]);
23.
putchar(ch);
24.
25.
}
}
Enter a sentence
wELCOME tO sANFOUNDRY
The given sentence is
: wELCOME tO sANFOUNDRY
Case changed sentence is: Welcome To Sanfoundry
int i = 0;
6.
7.
8.
if (argc == 1)
9.
10.
11.
return;
12.
13.
else
14.
15.
16.
/*
17.
18.
*/
19.
20.
21.
printf("\n%s", argv[i]);
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
Output
Enter elements: 1
2
3
5
4
You entered: 1
2
3
5
4
Output
#include <stdio.h>
void swap(int * q,int * p)
{
int temp = *p;
*p = *q;
*q = temp;
}
int main()
{
int a = 10, b = 2, x = 3, y = 5;
printf("a,b,x,y: %d,%d,%d,%d\n", a, b, x, y);
swap(&x, &y);
swap(&a, &b);
printf("a,b,x,y: %d,%d,%d,%d\n", a, b, x, y);
}
It will produces following result:
a,b,x,y: 10,2,3,5
a,b,x,y: 2,10,5,3
#include <stdio.h>
void get_array(int a[], int size);
void prt_array(int a[], int size);
#define SIZE 10
int main()
{
int a[SIZE];
get_array(a, SIZE);
prt_array(a, SIZE);
printf("\n");
return 0;
}
void get_array(int a[], int size)
{
int i;
printf("Enter 10 values, after each value press enter:\n " );
for (i = 0; i < size; i++)
scanf("%d", &a[i]);
}
void prt_array(int a[], int size)
{
int i;
Output :
1 #include<stdio.h>
2 #include<stdlib.h>
3 #define size 10
4
5 int main() {
6
7
8
10
11
12
return (0);
13 }
Output :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<stdio.h>
#include<conio.h>
int string_ln(char*);
void main() {
char str[20];
int length;
clrscr();
printf("\nEnter any string : ");
gets(str);
length = string_ln(str);
printf("The length of the given string %s is : %d", str, length);
getch();
}
int string_ln(char*p) /* p=&str[0] */
{
int count = 0;
while (*p != '\0') {
count++;
p++;
}
return count;
}
Output :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
//
a
3
i
i
void reduction(float a[][6], int size, int pivot, int col) {
int i, j;
float factor;
factor = a[pivot][col];
for (i = 0; i < 2 * size; i++) {
a[pivot][i] /= factor;
}
for (i = 0; i < size; i++) {
if (i != pivot) {
factor = a[i][col];
for (j = 0; j < 2 * size; j++) {
a[i][j] = a[i][j] - a[pivot][j] * factor;
}
}
}
}
void main() {
float matrix[3][6];
int i, j;
for (i = 0; i < 3; i++) {
for (j = 0; j < 6; j++) {
if (j == i + 3) {
matrix[i][j] = 1;
} else {
matrix[i][j] = 0;
}
}
}
printf("\nEnter a 3 X 3 Matrix :");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%f", &matrix[i][j]);
}
}
for (i = 0; i < 3; i++) {
reduction(matrix, 3, i, i);
}
printf("\nInvers Matrix");
for (i = 0; i < 3; i++) {
printf("\n");
for (j = 0; j < 3; j++) {
printf("%8.3f", matrix[i][j + 3]);
53
}
54 }
55 }
Output :
1
2
3
4
5
6
7
8
9
Enter a 3 X 3 Matrix
131
112
234
Invers Matrix
2.000 9.000 -5.000
0.000 -2.000 1.000
-1.000 -3.000 2.000