C language basic to Advance
2K subscribers
16 photos
2 videos
69 links
Download Telegram
Learn Telegram bot development using Nodejs telegraf library: https://www.youtube.com/playlist?list=PLjEYzWkdEvxvJ8lZacERw_NiUKbB7l_dx

1 more video added
Subscribe to get updates
Government ne google ki dadagiri ko khatm karne ke liye apna khud ka app store banaya hai 🔥😍

Playstore pe jo apps hain unhe 30% Playstore ko apni kamayi ka hissa dena padta hai

https://apps.mgov.gov.in/details?appid=270

Aap sabhi ye government playstore ko download kare Aur logo ko bhi share Kare

Government ne to apna Kam Kar diya ab hamari Bari.
👍2
// 1. Print all even numbers between 1 and 100 using a for loop:

#include <stdio.h>

int main() {
for(int i = 1; i <= 100; i++) {
if(i % 2 == 0) {
printf("%d\n", i);
}
}
return 0;
}
👍5
// 2. Calculate the sum of all odd numbers between 1 and 50 using a while loop:

#include <stdio.h>

int main() {
int sum = 0, i = 1;
while(i <= 50) {
if(i % 2 != 0) {
sum += i;
}
i++;
}
printf("Sum of all odd numbers between 1 and 50 is: %d\n", sum);
return 0;
}
// 3. Print the multiplication table of a given number using a for loop:

#include <stdio.h>

int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);

for(int i = 1; i <= 10; i++) {
printf("%d x %d = %d\n", num, i, num * i);
}
return 0;
}
// 4. Find the factorial of a given number using a for loop:
#include <stdio.h>

int main() {
int num, factorial = 1;
printf("Enter a number: ");
scanf("%d", &num);

for(int i = 1; i <= num; i++) {
factorial *= i;
}
printf("Factorial of %d is: %d\n", num, factorial);
return 0;
}
👍1
// 5. Check if a given number is prime or not using a for loop:

#include <stdio.h>

int main() {
int num, isPrime = 1;
printf("Enter a number: ");
scanf("%d", &num);

if (num <= 1) {
isPrime = 0;
} else {
for(int i = 2; i <= num / 2; i++) {
if(num % i == 0) {
isPrime = 0;
break;
}
}
}

if(isPrime) {
printf("%d is a prime number.\n", num);
} else {
printf("%d is not a prime number.\n", num);
}

return 0;
}
👍3
// 6. Print the Fibonacci series up to a given number using a for loop:

#include <stdio.h>

int main() {
int n, t1 = 0, t2 = 1, nextTerm;

printf("Enter the number of terms: ");
scanf("%d", &n);

printf("Fibonacci Series: %d, %d", t1, t2);

for(int i = 3; i <= n; i++) {
nextTerm = t1 + t2;
printf(", %d", nextTerm);
t1 = t2;
t2 = nextTerm;
}
printf("\n");
return 0;
}
👍1
// 7. Find the sum of all elements in an array using a for loop:

#include <stdio.h>

int main() {
int n, sum = 0;

printf("Enter the number of elements in the array: ");
scanf("%d", &n);

int arr[n];
printf("Enter the elements of the array:\n");
for(int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

for(int i = 0; i < n; i++) {
sum += arr[i];
}

printf("Sum of all elements in the array is: %d\n", sum);
return 0;
}
👍1
// 8. Find the largest element in an array using a for loop:
#include <stdio.h>

int main() {
int n;

printf("Enter the number of elements in the array: ");
scanf("%d", &n);

int arr[n];
printf("Enter the elements of the array:\n");
for(int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

int largest = arr[0];
for(int i = 1; i < n; i++) {
if(arr[i] > largest) {
largest = arr[i];
}
}

printf("The largest element in the array is: %d\n", largest);
return 0;
}
// 9. Find the smallest element in an array using a for loop:
#include <stdio.h>

int main() {
int n;

printf("Enter the number of elements in the array: ");
scanf("%d", &n);

int arr[n];
printf("Enter the elements of the array:\n");
for(int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

int smallest = arr[0];
for(int i = 1; i < n; i++) {
if(arr[i] < smallest) {
smallest = arr[i];
}
}

printf("The smallest element in the array is: %d\n", smallest);
return 0;
}
// 10. Reverse an array using a for loop:

#include <stdio.h>

int main() {
int n;

printf("Enter the number of elements in the array: ");
scanf("%d", &n);

int arr[n];
printf("Enter the elements of the array:\n");
for(int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

printf("Reversed array:\n");
for(int i = n-1; i >= 0; i--) {
printf("%d ", arr[i]);
}
printf("\n");

return 0;
}
👍2
// 11. Sort an array in ascending order using a for loop:

#include <stdio.h>

int main() {
int n;

printf("Enter the number of elements in the array: ");
scanf("%d", &n);

int arr[n];
printf("Enter the elements of the array:\n");
for(int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

for(int i = 0; i < n-1; i++) {
for(int j = i+1; j < n; j++) {
if(arr[i] > arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}

printf("Array in ascending order:\n");
for(int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");

return 0;
}
1
// 12. Sort an array in descending order using a for loop:

#include <stdio.h>

int main() {
int n;

printf("Enter the number of elements in the array: ");
scanf("%d", &n);

int arr[n];
printf("Enter the elements of the array:\n");
for(int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

for(int i = 0; i < n-1; i++) {
for(int j = i+1; j < n; j++) {
if(arr[i] < arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}

printf("Array in descending order:\n");
for(int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");

return 0;
}
1