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 print digit at one's place
--------------------------------------------------------
Program:
#include<stdio.h>
int main()
{int num,digit;
printf("Enter any number:");
scanf ("%d",&num);
digit=num%10;
printf("The digit at one's place of %d is %d",num,digit);
return 0;
}
----------------------------------------------------------
#basicprograms
👍11🔥5
Program to swap two numbers using third variable
----------------------------------------------------
Program:
#include<stdio.h>
int main()
{int a,b,temp;
printf("Enter a=");
scanf ("%d",&a);
printf("Enter b=");
scanf("%d",&b);
printf("Before Swapping:\n");
printf("a=%d\nb=%d",a,b);
temp=a;
a=b;
b=temp;
printf("\nAfter Swapping:");
printf("\na=%d\nb=%d",a,b);
return 0;
}
----------------------------------------------------
#basicprograms
👍24
Program to swap two numbers without using third variable
----------------------------------------------------
Program:
#include<stdio.h>
int main()
{int a,b;
printf("Enter a=");
scanf ("%d",&a);
printf("Enter b=");
scanf("%d",&b);
printf("Before Swapping:\n");
printf("a=%d\nb=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter Swapping:");
printf("\na=%d\nb=%d",a,b); return 0;
}
----------------------------------------------------
#basicprograms
👍25🥰4
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