C Programming Codes
13.4K subscribers
139 photos
2 videos
12 links
C Programming Codes || Quizzes || DSA

Learn along with the community

Any queries
admin - @Pradeep_saii
Download Telegram
Program to check whether entered year is leap year or not
----------------------------------------------------
Program:
#include<stdio.h>
int main()
{ int year;
printf("Enter ther year:");
scanf("%d",&year);
if(((year%4==0)&&(year%100!=0))||(year%400==0))
{
printf("%d is a leap year",year);
}
else
{
printf("%d is not a leap year",year);
}
return 0;
}
-------------------------------------------------------
#if_else
👍3610
Program to check whether entered number is positive, negative or zero using if else if statement
----------------------------------------------------
Program:
#include<stdio.h>
int main()
{ int num;
printf("Enter a number:");
scanf("%d",&num);
if(num>0)
{
printf("%d is a positive number",num);
}
else if(num==0)
{
printf("The entered number is equal to zero");
}
else
{
printf("%d is a negative number",num);
}
return 0;
}
----------------------------------------------------
#else_if
👍385😁2🤮1
Program to print largest among three numbers using if else if
----------------------------------------------------
Program:
#include <stdio.h>
int main()
{int num1, num2, num3;
printf("Enter three numbers: ");
scanf("%d%d%d", &num1, &num2, &num3);
if (num1 >= num2 && num1 >= num3) {
printf("%d is the largest number.\n", num1);
}
else if (num2 >= num1 && num2 >= num3) {
printf("%d is the largest number.\n", num2);
}
else {
printf("%d is the largest number.\n", num3);
}
return 0;
}
----------------------------------------------------
#else_if
👍258
Program to read the marks of a student in 4 subjects(100M per subject) and display todal marks, percentage and grade
------------------------------
Program:
#include <stdio.h>
int main()
{ int maths, physics, chemistry, electronics, total;
printf("Enter marks in Maths: ");
scanf("%d", &maths);
printf("Enter marks in Physics: ");
scanf("%d", &physics);
printf("Enter marks in Chemistry: ");
scanf("%d", &chemistry);
printf("Enter marks in Electronics: ");
scanf("%d", &electronics);
total = maths + physics + chemistry + electronics;
float percentage = (total / 400.0) * 100;
char grade;
if (percentage >= 90){
grade = 'A';
}
else if (percentage >= 80) {
grade = 'B';
}
else if (percentage >= 70) {
grade = 'C';
}
else if (percentage >= 60) {
grade = 'D';
}
else {
grade = 'F';
}
printf("Total marks: %d\n", total);
printf("Percentage: %.2f\n", percentage);
printf("Grade: %c\n", grade);
return 0;
}
--------------------------------
#else_if
👍56🥰15
Program to find roots of a quadratic equation.
--------------------------------------------
Program:
#include<stdio.h>
#include<math.h>
int main()
{ int a,b,c;
float D,denom,r1,r2;
printf("Enter the values of a,b,c:");
scanf("%d%d%d",&a,&b,&c);
D=(b*b)-(4*a*c);
denom=2*a;
if(D>0)
{r1=(-b+sqrt(D))/denom;
r2=(-b-sqrt(D))/denom;
printf("Real roots with,\n Root 1=%.2f\n Root 2=%.2f",r1,r2);
}
else if(D==0)
{r1=-b/denom;
r2=-b/denom;
printf("Equal roots with,\n Root 1=%.2f\n Root 2=%.2f",r1,r2);
}
else
{ r1=-b/denom;
r2=sqrt(-D)/denom;
printf("Imaginary Roots with,\n");
printf("Root 1=%.2f+%.2fi\n",r1,r2);
printf("Root 2=%.2f-%.2fi",r1,r2);
}
return 0;
}
-----------------------------------------
#else_if
👍24🔥6🥰4
program is written below 👇
👍12
Program to accept three numbers and print them in ascending and descending order
------------------------------------
Program:
#include<stdio.h>
  #include<math.h>
  int main()
  { int a,b,c;
    printf("Enter three numbers:");
    scanf("%d %d %d",&a,&b,&c);
    printf("Entered numbers are %d,%d,%d",a,b,c);
    printf("\n--------------------------------");
    if (a>=b && a>=c)
   {  if (b>=c){
       printf("\nDescending order : %d,%d,%d",a,b,c);
       printf("\nAscending order : %d,%d,%d",c,b,a);
      }
     else{
       printf("\nDescending order : %d,%d,%d",a,c,b);
       printf("\nAscending order : %d,%d,%d",b,c,a);
     }
   }
   else if (b>=a && b>=c) {
     if (a>=c){
        printf("\nDescending order: %d,%d,%d",b,a,c);
        printf("\nAscending order: %d,%d,%d",c,a,b);
     }
   }
    else{
     if (b>=a){
      printf("\nDescending order : %d,%d,%d",c,b,a);
      printf("\nAscending order : %d,%d,%d",a,b,c);
     }
     else {
      printf("\nDescending order : %d,%d,%d",c,a,b);
      printf("\nAscending order : %d,%d,%d",b,a,c);
     }
   }
   return 0;
  }
----------------------------------------
#else_if
👍67👨‍💻122🔥2🤩2🥰1👏1
Program to check whether entered character is vowel or consonant.
---------------------------------------------
Program:
#include <stdio.h>
int main()
{ char ch;
printf("Enter a character(lower case): ");
scanf("%c", &ch);
switch(ch)
{ case 'a':
printf("%c is a vowel.\n", ch);
break;
case 'e':
printf("%c is a vowel.\n", ch);
break;
case 'i':
printf("%c is a vowel.\n", ch);
break;
case 'o':
printf("%c is a vowel.\n", ch);
break;
case 'u':
printf("%c is a vowel.\n", ch);
break;
default:
printf("%c is a consonant.\n", ch);
}
return 0;
}
---------------------------------------------
#switch_case
👍271👌1
Program to enter a number between 1-7 and print the corresponding day of the week using switch case .
-------------------------------------------
Program:
#include<stdio.h>
int main()
{int day;
printf("Enter a number between 1-7:\n");
scanf("%d",&day);
switch (day)
{ case 1:
printf("Sunday\n");
break;
case 2:
printf("Monday\n");
break;
case 3:
printf("Tuesday\n");
break;
case 4:
printf("Wednesday\n");
break;
case 5:
printf("Thursday\n");
break;
case 6:
printf("Friday\n");
break;
case 7:
printf("Satuarday\n");
break;
default:
printf("You entered a wrong number");
}
return 0;
}
-------------------------------------------
#switch_case
👍61👎1
Program to check whether a number is even or odd using switch case.
-----------------------------------------
Program:
#include <stdio.h>

int main()
{ int num;
printf("Enter a number: ");
scanf("%d", &num);
switch (num % 2)
{ case 0:
printf("%d is even.\n", num);
break;
case 1:
printf("%d is odd.\n", num);
break;
}
return 0;
}
------------------------------------------
#switch_case
👍6
Program to make a simple calculator using Switch case.
-----------------------------------------
Program:
#include <stdio.h>
int main()
{
char operator;
float num1, num2, result;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operator);
printf("Enter two operands: ");
scanf("%f %f", &num1, &num2);
switch(operator)
{ case '+':
result = num1 + num2;
printf("%.2f + %.2f = %.2f", num1, num2, result);
break;
case '-':
result = num1 - num2;
printf("%.2f - %.2f = %.2f", num1, num2, result);
break;
case '*':
result = num1 * num2;
printf("%.2f * %.2f = %.2f", num1, num2, result);
break;
case '/':
result = num1 / num2;
printf("%.2f / %.2f = %.2f", num1, num2, result);
break;
default:
printf("Error: Invalid operator!");
break;
}
return 0;
}
------------------------------------------
#switch_case
👍51
Program to enter a number between 1-12 and print the corresponding month using switch case .
--------------------------
Program:
#include<stdio.h>
int main()
{ int month;
printf("Enter month number: ");
scanf("%d",&month);
switch(month)
{ case 1:
printf("January");
break;
case 2:
printf("February");
break;
case 3:
printf("March");
break;
case 4:
printf("April");
break;
case 5:
printf("May");
break;
case 6:
printf("June");
break;
case 7:
printf("July");
break;
case 8:
printf("August");
break;
case 9:
printf("September");
break;
case 10:
printf("October");
break;
case 11:
printf("November");
break;
case 12:
printf("December");
break;
default:
printf("Invalid month number");
break;
}
return 0;
}
---------------------------
#switch_case
👍7