0% found this document useful (0 votes)
2 views

C programming 21 november (1)

C programming basic programs

Uploaded by

jonadany2390
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C programming 21 november (1)

C programming basic programs

Uploaded by

jonadany2390
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Program 1

#include <stdio.h>

int main() {

int a, b, sum;

int *p1, *p2;

printf("Enter two numbers: ");

scanf("%d %d", &a, &b);

p1 = &a;

p2 = &b;

sum = *p1 + *p2;

printf("Sum = %d\n", sum);

return 0;

}
Program 2

#include <stdio.h>

int main()

int n, i;

printf("Enter the number of elements: ");

scanf("%d", &n);

int A[n];

int *p = A;

printf("Enter %d elements:\n", n);

for (i = 0; i < n; i++)

scanf("%d", (p + i));

printf("The elements are:\n");

for (i = 0; i < n; i++) {

printf("%d ", *(p + i));

return 0;

}
Program 3

#include <stdio.h>

int main()

char str[100];

char *p;

int length = 0;

printf("Enter a string: ");

scanf("%s", str);

p = str;

while (*p != '\0')

length++;

p++;

printf("Length of the string: %d\n", length);

return 0;

}
Program 4

#include <stdio.h>

void factorial(int *num, int *result)

*result = 1;

for (int i = 1; i <= *num; i++)

*result *= i;

int main()

int n, factorial;

printf("Enter a number: ");

scanf("%d", &n);

factorial(&n, &factorial);

printf("Factorial of %d is %d\n", n, factorial);

return 0;

}
Program 5

#include <stdio.h>

void countletter(char *str, int *strv, int *strc)

*strv = 0;

*strc = 0;

while (*str != '\0')

char c = *str;

if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))

if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||

c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')

(*strv)++;

else

(*strc)++;

str++;

int main()

char str[100];
int strv, strc;

printf("Enter a string: ");

scanf("%s", str);

countletter(str, &strv, &strc);

printf("Vowels: %d\n", strv);

printf("Consonants: %d\n", strc);

return 0;

}
Program 6

#include <stdio.h>

int main() {

int i, j, n, temp;

printf("Enter the number of elements of the array: ");

scanf("%d", &n);

int a[n];

int *ptr = a;

printf("Enter the elements of the array: ");

for (i = 0; i < n; i++) {

scanf("%d", &ptr[i]);

for (i = 0; i < n - 1; i++) {

for (j = 0; j < n - 1 - i; j++) {

if (*(ptr + j) < *(ptr + j + 1)) {

temp = *(ptr + j);

*(ptr + j) = *(ptr + j + 1);

*(ptr + j + 1) = temp;

}
printf("Sorted array: ");

for (i = 0; i < n; i++) {

printf("%d ", *(ptr + i)); }

printf("\n");

return 0;

You might also like