0% found this document useful (0 votes)
9 views

C++ Programming

The document contains code snippets for various C programming concepts like printing statements, arithmetic operations, increment/decrement operations, data type sizes, user input, calculations, and conditional statements. Each code sample takes input, performs some operation and prints output to demonstrate the concept.

Uploaded by

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

C++ Programming

The document contains code snippets for various C programming concepts like printing statements, arithmetic operations, increment/decrement operations, data type sizes, user input, calculations, and conditional statements. Each code sample takes input, performs some operation and prints output to demonstrate the concept.

Uploaded by

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

Print Hello World

Program:

#include <stdio.h>//Declaring libraries

int main(){//Main function

printf("Hello World");//Printing action

return 0;

Output
Perform arithmetic operation

Program:

#include <stdio.h>//Declaring libraries

int main(){//Main function

int a,b,c,d; //Declaring variables

a = 1 + 1; //Addition

b = 2-1; //Subtraction

c = 1*1; //Multiplication

d = 1/1; //Division

//Returning the output after doing arithmetic operations

printf("Addition of 1 and 1 is %d", a);

printf("\nSubtraction of 2 and 1 is %d", b);

printf("\nMultiplication of 1 and 1 is %d", c);

printf("\nDivision of 1 and 1 is %d",d);

return 0; //returning something after calling int main function

Output:
Perform increment and decrement operation.

Program:

#include <stdio.h>//Calling out libraries that we will use

int main(){ //Defining function

int a,b,c,d; //Declaring variables

a= 1, b =2; //Giving values to variables

c = a++;//Performing increment

d = b--;//Performing decrement

//Output

printf("The increment of %d is %d",a,c);

printf("\nThe decrement of %d is %d",b,d);

return 0; }

Output:
Display the size of int, char, float and double.

Program:

#include <stdio.h> //Calling out libraries that we will need

int main(){//Declaring a main function which is a integer

//Printing size of int, float, char and double.

printf("The size of integer is %d",sizeof(int));

printf("\nThe size of float is %d",sizeof(float));

printf("\nThe size of character is %d",sizeof(char));

printf("\nThe size of double is %d",sizeof(double));

return 0;//returning 0

Output:
Take marks of 5 subjects and calculate average
Program:

#include <stdio.h> //Calling out libraries that we will need

int main(){//Declaring a main function which is a integer

int math,science,computer,english,nepali;//Declaring variable to store marks

float avg; //Declaring variables to store average

//Taking students marks as input

printf("\nInput your math marks");

scanf("%d",& math);

printf("\nInput your science marks");

scanf("%d",& science);

printf("\nInput your science marks ");

scanf("%d",& computer);

printf("\nInput your english marks");

scanf("%d",& english);

printf("\nInput your nepali marks");

scanf("%d",& nepali);

avg = (math+science+computer+english+nepali)/5; //Calculation of averages

printf("\nThe average of students marks is %.2f",avg); //Showing output

return 0;//returning 0 }

Output:
Convert cm to m taking user input
Program:

#include <stdio.h> //Calling out libraries that we will need

int main(){//Declaring a main function which is a integer

float l,c; //Declaring variables to store length

//Taking length as input

printf("\nInput your length in cm");

scanf("%f",& l);

c = l/100;//calculation in m

//output

printf("\nYour length in m is %.1f", c);

return 0;//returning 0

Output:
Calculate the volume of cuboid
Program:

#include <stdio.h> //Calling out libraries that we will need

int main(){//Declaring a main function which is a integer

float l,b,h,c; //Declaring variables to store different dimensions and for calculation

//Taking dimensions as input

printf("\nInput your length ");

scanf("%f",& l);

printf("\nInput your breadth ");

scanf("%f",& b);

printf("\nInput your height ");

scanf("%f",&h);

c = l*b*h; //Calculation of volume

printf("\nYour volume is %.1f", c); //Output

return 0;//returning 0

Output:
Take user input money in dollar and convert it in Nepali rupees
Program:

#include <stdio.h> //Calling out libraries that we will need

int main(){//Declaring a main function which is a integer

float c,converted; //Declaring variables to store currency

//Taking currency as input

printf("\nInput your dollars currency ");

scanf("%f",& c);

converted = c * 133.06; //transforming dollar in nepali

printf("\nYour dollar is R$ %f", converted); //Output

return 0;//returning 0

Output:
Program:

#include <stdio.h> //Calling out libraries that we will need

int main(){//Declaring a main function which is a integer

int a,b; //Declaring variables to store numbers

//Taking numbers as input

printf("\nInput your first number ");

scanf("%d",& a);

printf("\nInput your second number ");

scanf("%d",& b);

if (a>b)

printf("%d is greater than %d",a,b);//output

return 0;

else
{

printf("%d is greater than %d",b,a); //Output

return 0;

printf("They are equal");

return 0;//returning 0

Output:

You might also like