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 accept three numbers and print largest among them
--------------------------------------------------
Program:
#include<stdio.h>
int main ()
{ int a,b,c;
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
printf("%d is greater than %d and %d",a,b,c);
if(b>a && b>c)
printf("%d is greater than %d and %d",b,a,c);
if(c>a && c>b)
printf("%d is greater than %d and %d",c,a,b);
return 0;
}
---------------------------------------------------
#if_statement
👍1714
Program to accept two numbers and print largest among them
------------------------------------------------
Program:
#include<stdio.h>
int main()
{ int a,b;
printf("Enter 1st number : ");
scanf("%d",&a);
printf("Enter 2nd number : ");
scanf("%d",&b);
if(a>b)
printf("%d is larger than %d",a,b);
else
printf("%d is larger than %d",b,a);
}
---------------------------------------------------
#if_else
👍224
Program to check whether a number is even or odd
--------------------------------------------------
Program:
#include<stdio.h>
int main()
{ int a;
printf("Enter a number : ");
scanf("%d",&a);
if(a%2==0)
printf("%d is an even number",a);
else
printf("%d is an odd number",a);
}
---------------------------------------------------
#if_else
👍121
Program to accept a character and if the entered character is lower case convert it into uppercase and if it is in upper case convert it into lowercase
---------------------------------------------------
Program:
#include<stdio.h>
int main()
{char ch;
printf("Enter a character:");
scanf("%c",&ch);
if(ch>='A'&&ch<='Z')
{printf("The entered character is in uppercase :%c\n",ch);
printf("The lowercase of above character is :%c",ch+32);
}
else
{printf("The entered character is in lowercase :%c\n",ch);
printf("The uppercase of above character is :%c",ch-32);
}
return 0;
}
---------------------------------------------------
#if_else
👍302
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);
if(ch=='a' ch=='e' ch=='i' ch=='o' ch=='u')
{
printf("%c is an vowel",ch);
}
else
{
printf("%c is a consonant ",ch);
}
return 0;
}
----------------------------------------------------
#if_else
friends or(||) operator is not getting printed in above text type as in image
👍40🔥43👏3🎉3👨‍💻3🤯1
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