C Programs
C Programs
#include <stdio.h>
void main()
{
int num;
printf("Enter a number: \n");
scanf("%d", &num);
if (num > 0)
printf("%d is a positive number \n", num);
else if (num < 0)
printf("%d is a negative number \n", num);
else
printf("0 is neither positive nor negative");
}
#include <stdio.h>
int main() {
return 0;
}
3. Factorial Program in C
#include <stdio.h>
int main() {
}
printf("Factorial of %d is %d",num,fact);
return 0;
}
#include<stdio.h>
int main()
{
int a=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swap a=%d b=%d",a,b);
return 0;
}
6. Program to Check Leap Year
#include <stdio.h>
int main()
{
int year;
printf("Enter year:");
scanf("%d",&year);
if((year%4==0) && (year%100!=0)||(year%400==0))
printf("%d year is a Leap Year",year);
else
printf("%d year is not a Leap Year",year);
return 0;
}
void main()
{
int r;
float PI = 3.14, area, ci;
printf("\nEnter the radius of the circle: ");
scanf("%d", &r);
area = PI*r*r;
printf("\n\n\n Area of the circle is: %f ", area);
ci = 2*PI*r;
printf("\n\n\n Circumference of the circle is: %f", ci);
10. C Program to find the Area of Triangle using Base and Height
#include<stdio.h>
void main()
{
int h, b;
float area;
printf("\n\nEnter the base and height of the Triangle: ");
scanf("%d%d",&b, &h);
area = 0.5*(h*b);
printf("\n\n\nThe area of the triangle is: %f", area);
}
#include<stdio.h>
void main()
{
float cel, fah;
printf("\n\nEnter temperature in fah: ");
scanf("%f", &fah);
int main()
{
float km, m;
m = km * 1000;
return 0;
}
16. C program to find sum of the square of all natural numbers from 1 to N.
Series: 1^2+2^2+3^2+4^2+..N^2
#include<stdio.h>
int main()
{
int i,N;
int sum=0;
printf("Enter the value of N: ");
scanf("%d",&N);
for(i=1;i<=N;i++)
sum= sum+ (i*i);
printf("Sum of the series is: %d\n",sum);
return 0;
}
#include<stdio.h>
#include<math.h>
int main()
{
int n1,n2,i,p;
printf("Enter limit");
scanf("%d%d",&n1,&n2);
for(i=n1;i<=n2;i++){
p=sqrt(i);
if(p*p==i)
{
printf("%d\n",i);
}
}
return 0;
}
if (n1 == rev){
printf("Given number is a palindrome number");
}
else{
printf("Given number is not a palindrome number");
}
return 0;
}
return 0;
}
#include<stdio.h>
void main()
{
int hindi, english, science,math,computer,sum ;
float per;
printf("Enter marks of Hindi=");
scanf("%d",&hindi);
printf("Enter marks of English=");
scanf("%d",&english);
printf("Enter marks of Science=");
scanf("%d",&science);
printf("Enter marks of Math=");
scanf("%d",&math);
printf("Enter marks of Computer=");
scanf("%d",&computer);
sum=hindi+english+science+math+computer;
printf("\nSum of marks=%d",sum);
per=(float)sum/5;
printf("\nPercentage of marks=%f",per);
if(per>=90&&per<=100)
{
printf("\nGrade A");
}
else if(per>=80&&per<90)
{
printf("\nGrade B");
}
else if(per>=60&&per<80)
{
printf("\nGrade C");
}
else if(per<60)
{
printf("\nGrade D");
}
}
int main() {
double number, squareRoot;
squareRoot = sqrt(number);
return 0;
}