244 subscribers
6 photos
3 files
4 links
This group will help beginners to learn programming in C language.

Discussion: @c_coding_discussion
Download Telegram
Channel created
Here you will get codes of DSUS (DSA) and all basic to advanced code of C language
#notice:
Do not copy paste these codes try to understand the concept of the code.
#If you have any query or doubt in c programming you can ask me directly.

Thanks to all for joining the group...
Happy coding :)
1. First C program :-

#include <stdio.h>

int main() {
printf ("Hello World!");
return 0;
}

2. C program to add two integers:-
#include <stdio.h>

int main() {
int a = 5, b = 4;
printf ("sum = %d",(a+b));
return 0;
}
👍1
3. C program to subtraction of two integers:-
#include <stdio.h>

int main() {
int a = 5, b = 4;
int c;
c = a-b;
printf ("subtraction = %d",c);
return 0;
}
👍2
4. C program to add and subtract two integers on user based input:-
#include <stdio.h>

int main() {
int a,b;
int sum =0, sub = 0;
printf("enter two numbers: \n");
scanf("%d %d",&a,&b);
sum = a+b;
sub = a-b;
printf("sum = %d\nsub = %d", sum, sub);
return 0;
}
Programmed by: @miss_rupali
👍2
5. Program to print n natural numbers:-
#include <stdio.h>
int main() {
printf ("***NATURAL NUMBERS***\n");
int a,b;
printf("Enter a number:\n");
scanf("%d\n",&a);
printf ("Enter second number:\n");
scanf ("%d\n",&b);
for(int i=a;i<=b;i++){
printf ("%d\n",i);
}

return 0;
}
👍1
6. C program to check whether a number is Armstrong number or not:-
#include <stdio.h>
// armstrong number in c
int main() {
int rem, num, sum=0, temp;
printf ("Enter a number: ");
scanf("%d", &num);
temp = num;

while(num > 0){
rem = num % 10;
sum += (rem*rem*rem);
num /= 10;
}

if(temp == sum){
printf ("Armstrong number!");
}
else {
printf ("Not a armstrong number!");
}
return 0;
}
7. C program to find the next date of menstrual cycle according to months:-
#include <stdio.h>
/*
{
input format: you have to give first number for periods date and second for total days of a month
for example: 24 30 output will be 22
}*/
int main() {
// int month = 31;
int m;
int date;
int nextDate;
printf ("Enter a valid date and month(28 or 31 or 30):");
scanf("%d %d",&date,&m);
if(date >31){
printf ("Enter a valid date\n");
}
else{
switch (m){
case 28:
nextDate = 28+date-m;
break;
case 30:
nextDate = 28+date-m;
break;
case 31:
nextDate = 28+date-m;
break;
default:
printf("Invalid month");
}

}
printf("Next Date = %d",nextDate );
return 0;
}
👍1
8. Write a program in C to copy a string value from variable to another using user defined functions.
#include <stdio.h>

void copy(char str1[300], char str2[300]){
int i;
for(i =1; str1[i] != '\0'; i++){
str2[i] = str1[i];
}
str2[i] = '\0';
printf("%s is copied into %s",str1, str2);
}
int main()
{
char str1[300];
char str2[300];
printf("Enter firdt string: ");

//for taking a string with white spaces we will use gets() function otherwise we will use scanf() function
// scanf("%s", str1);
gets(str1);
printf("Enter your second string: ");
// scanf("%s", str2);
gets(str2);
copy(str1, str2);
return 0;
}