c programming solution
write a c program to calculate sum of two different integer
#include <stdio.h> int main() { int x, y, sum; printf("\nInput the first integer: "); scanf("%d", &x); printf("\nInput the second integer: "); scanf("%d", &y); sum = x + y; printf("\nSum of the above two integers = %d\n", sum); return 0; }
Flowchart
Write a c program to calculate area of circle
#include <stdio.h>
int main() {
float radius, area_circle;
// take radius as input
printf("Enter the radius of circle : ");
scanf("%f", &radius);
area_circle = 3.14 * radius * radius;
printf("Area of circle : %f", area_circle);
return 0;
}
flowchart
write a c program to calculate permieter of circle
#include <stdio.h>
#define PI 3.1416
int main() {
double radius, perimeter;
printf("Enter the radius: ");
scanf("%lf", &radius);
perimeter = 2*PI*radius;
printf("The perimeter is: %0.2lf\n", perimeter);
return 0;
}
flowchart
write a c progam to calculate the volume
//Finds volume of a box
#include<stdio.h>
void main()
{
int length,width, height;
float volume=0;
printf("\nFinds volume of a box\n-------------------");
printf("\nEnter length: ");
scanf("%d", &length);
printf("\nEnter width: ");
scanf("%d", &width);
printf("\nEnter height: ");
scanf("%d", &height);
volume = (length*width*height);
printf("Volume of a box is: %.2f", volume);
}
flowchartwrite a c program to calculate the simple intrest
/**
* C program to calculate simple interest
*/
#include <stdio.h>
int main()
{
float principle, time, rate, SI;
/* Input principle, rate and time */
printf("Enter principle (amount): ");
scanf("%f", &principle);
printf("Enter time: ");
scanf("%f", &time);
printf("Enter rate: ");
scanf("%f", &rate);
/* Calculate simple interest */
SI = (principle * time * rate) / 100;
/* Print the resultant value of SI */
printf("Simple Interest = %f", SI);
return 0;
}
flowchartcontrol statement
write a c program to check the given number is postive or negative or zero
#include <stdio.h>
int main()
{
int A;
printf("Enter the number A: ");
scanf("%d", &A);
if (A > 0)
printf("%d is positive.", A);
else if (A < 0)
printf("%d is negative.", A);
else if (A == 0)
printf("%d is zero.", A);
return 0;
}
flowchart
write a c program to check the given number is odd or even
#include <stdio.h>
int main()
{
int a;
printf("Enter a: ");
scanf("%d", &a);
//logic
if (a % 2 == 0) {
printf("The given number is EVEN");
}
else {
printf("The given number is ODD");
}
return 0;
}
flowchartwrite a c program to check pass or fall
#include <stdio.h>
int main(void) {
int Per;
printf("Enter Per : ");
scanf("%d",&Per);
if(Per >= 40)
printf("\nResult is pass");
else
printf("\nResult is fail");
return 0;
}
flowchart
write a c program the day by using equivalent numbers
#include <stdio.h>
void main()
{
int dayno;
printf("Input Day No : ");
scanf("%d",&dayno);
switch(dayno)
{
case 1:
printf("Monday \n");
break;
case 2:
printf("Tuesday \n");
break;
case 3:
printf("Wednesday \n");
break;
case 4:
printf("Thursday \n");
break;
case 5:
printf("Friday \n");
break;
case 6:
printf("Saturday \n");
break;
case 7:
printf("Sunday \n");
break;
default:
printf("Invalid day number. \nPlease try again ....\n");
break;
}
}
flowchartwrite a c program Print your name, date of birth, and mobile number
#include <stdio.h>
int main()
{
printf("Name : Alexandra Abramov\n");
printf("DOB : July 14, 1975\n");
printf("Mobile : 99-9999999999\n");
return(0);
}
flowchart
switch statements
write a c program to find grade of a student using switch case statement
#include<stdio.h>
int main()
{
int score;
printf("Enter score( 0-100 ): ");
scanf("%d", &score);
switch( score / 10 )
{
case 10:
case 9:
printf("Grade: A");
break;
case 8:
printf("Grade: B");
break;
case 7:
printf("Grade: C");
break;
case 6:
printf("Grade: D");
break;
case 5:
printf("Grade: E");
break;
default:
printf("Grade: F");
break;
}
return 0;
}
flowchartloop
write a c goto progam to print natural number
#include <stdio.h>
int main()
{
int counter=1;
int n;
//enter the value of n (range)
printf("Enter the value of n: ");
scanf("%d",&n);
//define label
START:
printf("%d ",counter);
counter++; //increment counter
//condition & goto statement
if(counter<=n)
goto START;
return 0;
}
flowchart
write a c program to display 1 to 100 natural number
#include<stdio.h>
int main(){
int i;
//Print numbers from 1 to 100
for(i = 1; i <= 100; i++){
printf("%d ",i);
}
return 0;
}
flowchart write a c progam to display 1 to 100 even number
#include<stdio.h>
int main(){
for(int i=1;i<=100;i++)
{
// if number module i is equal to 0, then number is even
if(i%2==0)
{
printf("%d\n", i);
}
}
return 0;
}
flowchart
write a c program to display 1 to 100 sum
#include <stdio.h>
int main() {
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
sum += i;
}
printf("Sum = %d", sum);
return 0;
}
flowchart
write a c program to display 3,7,11... 15th terms
#include<stdio.h>
#include<conio.h>
void main()
{
int s=3, i;
for ( i = 1; i <=15; i++)
{
printf("%d \t",s);
s=s+4;
}
getch();
}
flowchartwrite a c program to display 5,10,15...20th terms sum
#include<stdio.h>
#include<conio.h>
void main()
{
int s=5, i, sum=0;
for ( i = 1; i <=20; i++)
{
printf("%d \t",s);
sum=sum+s;
s=s+5;
}
printf("The sum is %d \n",sum);
getch();
}
flowchart
write a c program given number is prime or composit
#include<stdio.h>
int main()
{
int i,n,c=0;
printf ("Enter a number \t");
scanf ("%d",&n);
for (i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
if (c==2)
printf ("The number is PRIME");
else
printf ("The number is COMPOSITE");
return 0;
}
flowchart
write a c program to display multiplication tables
#include <stdio.h>
int main() {
int n, i;
printf("Enter an integer: ");
scanf("%d", &n);
for (i = 1; i <= 10; ++i) {
printf("%d * %d = %d \n", n, i, n * i);
}
return 0;
}
flowchart