0% found this document useful (0 votes)
84 views14 pages

NAME 116 Programs

Uploaded by

Barnil Samiu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views14 pages

NAME 116 Programs

Uploaded by

Barnil Samiu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

8/29/2018 NAME 116

C Programming

A. K. M. Samiu Haque Barnil


// 01.Celsius to Fahrenheit

#include<stdio.h>
int main()
{
double C, F;
printf("Temperature in Celsius:\n");
scanf("%lf", &C);
F = 1.8*C+32;
printf("Temperature in Fahrenheit: %0.2lf\n", F);

return 0;
}

// 02.Swap two number

#include<stdio.h>
int main()
{
int a, b, c;
printf("Enter the First Number:");
scanf("%d", &a);
printf("\nEnter the Second Number:");
scanf("%d", &b);
c=a;
a=b;
b=c;
printf("\n%d %d", a,b);

return 0;
}
// 03.Increase if negative or zero, Decrease if positive

#include<stdio.h>

int main()
{
int i;
printf("Enter a Number:");
scanf("%d", &i);
if(i>0)
{
--i;
}
else
{
++i;
}
printf("%d", i);

return 0;
}
// 04.Minimum number among three integer

#include<stdio.h>

int main()
{
int a,b,c,m;
printf("Enter the First Number:");
scanf("%d", &a);
printf("\nEnter the Second Number:");
scanf("%d", &b);
printf("\nEnter the Third Number:");
scanf("%d", &c);
if(a<=b && a<=c)
{
m=a;
}
if(b<=a && b<=c)
{
m=b;
}
if(c<=a && c<=b)
{
m=c;
}

printf("The Minimum Number is %d", m);

return 0;
}
// 05.Positive, Negative or Zero

#include<stdio.h>

int main()
{
int a;
printf("Enter a Number:");
scanf("%d", &a);
if(a>0)
{
printf("The number is positive");
}
else if(a<0)
{
printf("The number is negative");
}
else
{
printf("The number is zero");
}

return 0;
}
// 06.Odd or Even

#include<stdio.h>

int main()
{
int a;
printf("Enter a Number:");
scanf("%d", &a);
if(a%2==0)
{
printf("The number is Even");
}
else
{
printf("The number is Odd");
}

return 0;
}
// 07.Vowel or Consonant

#include<stdio.h>
int main()
{
char ch;
printf("Enter an Alphabet:");
scanf("%c", &ch);
if(ch>='a' && ch<='z' || ch>='A' && ch<='Z')
{
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' ||
ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
printf("Vowel");
}
else
{
printf("Consonant");
}

}
else
{
printf("Error");
}

return 0;
}
// 08.Last digit divisible by three

#include<stdio.h>

int main()
{
int a,b;
printf("Enter a Number:");
scanf("%d", &a);
b=a%10;
if(b%3==0)
{
printf("The last digit is divisible by 3");
}
else
{
printf("The last digit is not divisible by 3");
}

return 0;
}
// 09.Leap Year

#include<stdio.h>

int main()
{
int a;
printf("Enter a Number:");
scanf("%d", &a);
if(a%4==0 && a%100!=0 || a%400==0)
{
printf("It is a leap year");
}
else
{
printf("It is not a leap year");
}

return 0;
}
// 10.First n-th Natural Number

#include<stdio.h>

int main()
{
int n, i;
printf("Enter the value of n:");
scanf("%d", &n);
for(i=1;i<=n;i++)
{
printf("%d\n", i);
}

return 0;

}
// 11.Sum and Average of 10 numbers

#include<stdio.h>

int main()
{
double a, i, sum=0, avg;
printf("Enter 10 Numbers:\n");
for(i=1;i<=10;i++)
{
scanf("%lf", &a);
sum=sum+a;
}
avg=sum/10;
printf("Sum=%0.2lf\n", sum);
printf("Average=%0.2lf\n", avg);

return 0;
}
// 12.Multiplication table

#include<stdio.h>

int main()
{
int a, i;
printf("Input the Number:");
scanf("%d", &a);
for(i=1;i<=10;i++)
{
printf("%d X %d = %d\n", a,i,a*i);
}

return 0;
}
// 13.Factorial

#include<stdio.h>

int main()
{
int a, f=1, i;
printf("Input the Number:");
scanf("%d", &a);
for(i=1;i<=a;i++)
{
f=f*i;
}
printf("The factorial is:%d", f);

return 0;
}
// 14.First 10 odd numbers and their sum

#include<stdio.h>

int main()
{
int i, sum=0;
printf("First 10 odd numbers are:\n");
for(i=1;i<=20;i=i+2)
{
printf("%d\n", i);
sum=sum+i;
}
printf("Sum=%d", sum);

return 0;
}

You might also like