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 calculate average of two numbers and print their deviation
----------------------------------------------------
Program:
#include<stdio.h>
int main()
{int a,b;
float avg,d1,d2;
printf("Enter first number=");
scanf ("%d",&a);
printf("Enter second number=");
scanf("%d",&b);
avg=(a+b)/2;
d1=a-avg;
d2=b-avg;
printf("Average=%.2f\n",avg);
printf("Deviation of 1st number (i.e %d) is=%.2f",a,d1);
printf("\nDeviation of 2nd number (i.e %d) is=%.2f",b,d2);
return 0;
}
----------------------------------------------------
#basicprograms
👍31🙏3❤‍🔥2
Program to know the size of data type
----------------------------------------------------
Program:
#include<stdio.h>
int main()
{
printf("Size of int:%d bytes\n",sizeof(int));
printf("Size of float:%d bytes\n",sizeof(float));
printf("Size of char:%d bytes\n",sizeof(char));
printf("Size of double:%d bytes\n",sizeof(double));
return 0;
}
----------------------------------------------------
#basicprograms
👍18👏11🔥6🥰6
Program to convert floating point number into int.
----------------------------------------------------
Program:
#include<stdio.h>
int main()
{float a;
int b;
printf("enter floating point number:");
scanf("%f",&a);
b=(int)a;
printf("%d",b);
return 0;
}
----------------------------------------------------
#basicprograms
👍44🔥4👏3👎1
Program to check vote eligibilty if not eligible tell him/her how many years he/she should wait for eligibilty using if statement
-----------------------------------------------------
Program:
#include<stdio.h>
int main()
{ int a;
printf("Enter your age:");
scanf("%d",&a);
if(a>=18)
{
printf("Your age is %d you are eligible to vote",a);
}
if(a<18)
{ a=18-a;
printf("You should wait %dyrs for eligibilty",a);
}
return 0;
}
----------------------------------------------------
#if_statement
👍409🥰7
Program to check whether entered number is positive, negative or zero using if statement
----------------------------------------------------
Program:
#include<stdio.h>
int main ()
{ int a;
printf("Enter a number:");
scanf("%d",&a);
if(a>0)
printf("%d is a positive number",a);
if(a==0)
printf("%d is neither positive nor negative",a);
if(a<0)
printf("%d is a negative number",a);
return 0;
}
----------------------------------------------------
#if_statement
👍26
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);
if(a%2!=0)
printf("%d is a odd number",a);
return 0;
}
-----------------------------------------------------
#if_statement
👍265🔥3
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