Dropdowns

/*Program to find the LCM and HCF of two numbers*/ #include<stdio.h> int main(void) { int x,y,a,b; printf(“Enter two numbers : “); scanf(“%d%d”,&x,&y); a=x; b=y; while(a!=b) { if(ab) a=a-b; else b=b-a; } printf(“HCF of %d and %d is %d\n”,x,y,a); return 0; } Output: Enter two numbers : 36 48 LCM of 36 and 48 is 144 […]

c language tutorial learn c language study c language

/*P5.41 Program to find day of week from a given date*/ #include<stdio.h> int main(void) { int d,m,y,j,f,h,fh,day; printf(“Enter date(dd/mm/yyyy): “); scanf(“%d/%d/%d”,&d,&m,&y); j=d; switch(m-1) { case 11: j+=30; /*Fall thru in all cases*/ case 10: j+=31; case 9: j+=30; case 8: j+=31; case 7: j+=31; case 6: j+=30; case 5: j+=31; case 4: j+=30; case 3: […]

c language tutorial learn c language study c language

/*Program to get difference of two dates in years, months, days*/ #include<stdio.h> int main(void) { int d1,d2,d,m1,m2,m,y1,y2,y; printf(“Enter first date(dd/mm/yyyy): “); scanf(“%d/%d/%d”,&d1,&m1,&y1); printf(“Enter second date(dd/mm/yyyy): “); scanf(“%d/%d/%d”,&d2,&m2,&y2); if(d2<d1) { if(m2==3) { if(y2%100!=0 && y2%4==0 || y2%400==0) /*check for leap year*/ d2=d2+29; else d2=d2+28; } else if(m2==5 || m2==7 || m2==10 || m2==12) d2=d2+30; else d2=d2+31; […]

c language tutorial learn c language study c language

/*Program to check whether a date is valid or not*/ #include<stdio.h> int main(void) { int d,m,y; int flag=1,isleap=0; printf(“Enter date(dd/mm/yyyy): “); scanf(“%d/%d/%d”,&d,&m,&y); if(y%100!=0 && y%4==0 || y%400==0) isleap=1; if(y2050 || m12 || d31) flag=0; else if(m==2) /*Check for number of days in February*/ { if(d==30 || d==31 || (d==29 && !isleap) ) flag=0; } else […]

c language tutorial learn c language study c language

/*P5.36 A menu driven program using infinite loop and switch*/ #include<stdio.h> int main(void) { int choice; while(1) { printf(“1.Create database\n”); printf(“2.Insert new record\n”); printf(“3.Modify a record\n”); printf(“4.Delete a record\n”); printf(“5.Display all records\n”); printf(“6.Exit\n”); printf(“Enter your choice : “); scanf(“%d”,&choice); switch(choice) { case 1: printf(“Database created…..\n\n”); break; case 2: printf(“Record inserted…..\n\n”); break; case 3: printf(“Record modified…..\n\n”); […]

c language tutorial learn c language study c language

/*P5.35 Program to find whether the alphabet is a vowel or consonant*/ #include<stdio.h> int main(void) { char ch; printf(“Enter an alphabet : “); scanf(“%c”,&ch); switch(ch) { case ‘a’: case ‘e’: case ‘i’: case ‘o’: case ‘u’: printf(“Alphabet is a vowel\n”); break; default: printf(“Alphabet is a consonant\n”); } return 0; } Output: Enter an alphabet : […]

c language tutorial learn c language study c language

/*Program to perform arithmetic calculations on integers*/ #include<stdio.h> int main(void) { char op; int a,b; printf(“Enter number,operator and another number : “); scanf(“%d%c%d”,&a,&op,&b); switch(op) { case ‘+’: printf(“Result = %d\n”,a+b); break; case ‘-‘: printf(“Result = %d\n”,a-b); break; case ‘*’: printf(“Result = %d\n”,a*b); break; case ‘/’: printf(“Result = %d\n”,a/b); break; case ‘%’: printf(“Result = %d\n”,a%b); break; […]

c language tutorial learn c language study c language

/*Multiply two positive numbers without using * operator*/ #include<stdio.h> int main(void) { int a,b,i; int result=0; printf(“Enter two numbers to be multiplied : “); scanf(“%d%d”,&a,&b); for(i=1; i

c language tutorial learn c language study c language

/*Program to count digits in a number */ #include<stdio.h> int main(void) { int n,count=0,rem; printf(“Enter a number : “); scanf(“%d”,&n); do { n/=10; count++; }while(n>0); printf(“Number of digits=%d\n”,count); return 0; } Output: Enter a number : 24512 Number of digits=5

c language tutorial learn c language study c language

/*Program to find the product of digits of any number*/ #include<stdio.h> int main(void) { int n,prod=1,rem; printf(“Enter a number : “); scanf(“%d”,&n); while(n>0) { rem = n%10; /*taking last digit of n*/ prod*=rem; n/=10; /*skipping last digit of n*/ } printf(“Product of digits = %d\n”,prod); return 0; } Output: Enter a number : 12345 Product […]

c language tutorial learn c language study c language
On this page