// 18. Write a C program to find the LCM of two numbers using a while loop:
#include <stdio.h>
int main() {
int num1, num2, max;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
max = (num1 > num2) ? num1 : num2;
while (1) {
if (max % num1 == 0 && max % num2 == 0) {
printf("LCM: %d", max);
break;
}
max++;
}
return 0;
}
👍1
// 19. Write a C program to print all Armstrong numbers between 1 and 1000 using a for loop:
#include <stdio.h>
#include <math.h>
int main() {
int num, originalNum, remainder, result = 0, n = 0;
printf("Armstrong numbers between 1 and 1000: ");
for (num = 1; num <= 1000; num++) {
originalNum = num;
while (originalNum != 0) {
originalNum /= 10;
++n;
}
originalNum = num;
while (originalNum != 0) {
remainder = originalNum % 10;
result += pow(remainder, n);
originalNum /= 10;
}
if (result == num) {
printf("%d ", num);
}
n = 0;
result = 0;
}
return 0;
}
// 20. Write a C program to print all perfect numbers between 1 and 1000 using a for loop:
/*
Perfect number vo number hota hai jo apne divisors ke sum ke barabar hota hai
For example 6 ek Perfect number hai
Agar in divisors ko sum kare to 6 hi aayega
*/
#include <stdio.h>
int main() {
int i, num, sum;
printf("Perfect numbers between 1 and 1000: ");
for (num = 1; num <= 1000; num++) {
sum = 0;
for (i = 1; i < num; i++) {
if (num % i == 0) {
sum += i;
}
}
if (sum == num) {
printf("%d ", num);
}
}
return 0;
}
/*
Perfect number vo number hota hai jo apne divisors ke sum ke barabar hota hai
For example 6 ek Perfect number hai
6 ke divisors 1, 2, 3
Agar in divisors ko sum kare to 6 hi aayega
1 + 2 + 3 == 6
*/
👍2❤1🥰1
20 questions related to c loops
https://t.me/C_Codes_pro/184
Answers 🔥 (can run also)
https://t.me/C_Codes_pro/212
Your 10 to 30 numbers is final in c if you practice these 20 questions
https://t.me/C_Codes_pro/184
Answers 🔥 (can run also)
https://t.me/C_Codes_pro/212
Your 10 to 30 numbers is final in c if you practice these 20 questions
👍2❤1🥰1
C language basic to Advance pinned «20 questions related to c loops https://t.me/C_Codes_pro/184 Answers 🔥 (can run also) https://t.me/C_Codes_pro/212 Your 10 to 30 numbers is final in c if you practice these 20 questions»
🥰1
Select your group/channel/service
t.me/Sid_info/69
t.me/Sid_info/69
🥰1
// udp server program
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define PORT 8888
#define MAX_BUFFER_SIZE 1024
int main() {
int sockfd;
struct sockaddr_in serverAddr, clientAddr;
socklen_t addrLen = sizeof(clientAddr);
char buffer[MAX_BUFFER_SIZE];
// Creating socket file descriptor
if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
perror("Socket creation error");
exit(EXIT_FAILURE);
}
memset(&serverAddr, 0, sizeof(serverAddr));
memset(&clientAddr, 0, sizeof(clientAddr));
serverAddr.sin_family = AF_INET;
serverAddr.sin_addr.s_addr = INADDR_ANY;
serverAddr.sin_port = htons(PORT);
// Bind the socket to the specified port
if (bind(sockfd, (const struct sockaddr *)&serverAddr, sizeof(serverAddr)) == -1) {
perror("Bind error");
exit(EXIT_FAILURE);
}
printf("UDP server running on port %d\n", PORT);
// Receive data from clients indefinitely
while (1) {
int bytesReceived = recvfrom(sockfd, (char *)buffer, MAX_BUFFER_SIZE, 0, (struct sockaddr *)&clientAddr, &addrLen);
buffer[bytesReceived] = '\0'; // Null-terminate the received data
printf("Received message from client: %s\n", buffer);
}
return 0;
}
👍2🤬2❤1
// udp client program
/*
If you want run udp server and client program here then use 2 telegram id
First run udp server program from 1st id
Then run udp client program from second id
Otherwise it will give error
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define PORT 8888
#define SERVER_IP "127.0.0.1"
int main() {
int sockfd;
struct sockaddr_in serverAddr;
char *message = "Hello, UDP Server!";
// Creating socket file descriptor
if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
perror("Socket creation error");
exit(EXIT_FAILURE);
}
memset(&serverAddr, 0, sizeof(serverAddr));
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(PORT);
serverAddr.sin_addr.s_addr = inet_addr(SERVER_IP);
// Send a message to the server
if (sendto(sockfd, (const char *)message, strlen(message), 0, (const struct sockaddr *)&serverAddr, sizeof(serverAddr)) == -1) {
perror("Sendto error");
exit(EXIT_FAILURE);
}
printf("Message sent to server: %s\n", message);
close(sockfd);
return 0;
}
/*
If you want run udp server and client program here then use 2 telegram id
First run udp server program from 1st id
Then run udp client program from second id
Otherwise it will give error
*/
👍6
Everything related to coding 👇
https://t.me/addlist/2UhsQW_cGzkxMzg1
https://t.me/addlist/2UhsQW_cGzkxMzg1
Apna khud ka Compiler bot run karna ab bahut simple hai
Bas iocompiler lib install karo aur code run kardo 👇ye dekho poori details
https://t.me/logicBots/207
Bas iocompiler lib install karo aur code run kardo 👇ye dekho poori details
https://t.me/logicBots/207
👍3
C language
https://youtu.be/GPat5ENZytg
C language samajhane ke liye har tarah ka prayas 👇
By defination
By real life example
By in deep memory how c works
By codes examples
By practical code run
https://youtu.be/GPat5ENZytg
C language samajhane ke liye har tarah ka prayas 👇
By defination
By real life example
By in deep memory how c works
By codes examples
By practical code run
👍4🥰2❤1
Create compiler bot in mobile
Run any language codes
In hindi:
Ab laptop ko kar do Tata bye bye gya 😂
https://youtu.be/352o8B9IikI?si=OSrhBU0mcFEkqILA
Run any language codes
In hindi:
Ab laptop ko kar do Tata bye bye gya 😂
https://youtu.be/352o8B9IikI?si=OSrhBU0mcFEkqILA
YouTube
How to create compiler bot and run c/c++ java python node js ts from mobile as server in termux
How to create compiler bot and run c/c++ java python node js ts from mobile as server in termux
Create own compiler bot in 2 minutes
Overview:
In this video, I exaplained You about how to use clone Compiler bot to create your own compiler bot.
keys:…
Create own compiler bot in 2 minutes
Overview:
In this video, I exaplained You about how to use clone Compiler bot to create your own compiler bot.
keys:…
👍1