C Code
C Code
#include <iostream>
1, int main()
{
int num1 = 55, num2 = 24, mod;
mod =num1 % num2;
4, cout << "((3==3) && (3<5))=" <<((3==3) && (3<5)) << endl;
cout << "((3>3) && (3<5)="<<((3>3) && (3<5))<<endl;
cout << "((3!=) && (3>5)="<<((3!=3) && (3>5))<<endl;
5, int a=5;
int b = a++; //assign -> update
cout << b<<endl;//5
cout << a<<endl;//6
6, /int a =5;
int b =++a; // update -> assign
cout <<b<< endl; //5
cout <<a<< endl; //6
7, int age;
cout<<"Enter your age";
cin>>age;
if(age<=0)
{cout<<"Invalid Age"<<endl;}
else{
cout<<age
}
return 0;
}
8, int score;
cout<<"Enter your Marks:";
cin>>score;
if(score >=90){
cout<< "Grade A" <<endl;
}
else if(score>=80 && score < 90){
cout<<"Grade B" << endl;
}
else if (score>=70 && score < 80){
cout << "Grade C" << endl;
}
else{
cout<<"Fail"<<endl;
}
return 0;
9, int number;
cout<<"Enter a Number:";
cin>>number;
if(number>=0){
cout<<"Positive Number"<<endl;
}
else{
cout<< "Negative Number"<<endl;
return 0;
10, #include <iostream>
int main ()
{
cout << "size of int is:" << sizeof(int)<< "Bytes" << endl;
cout << "size of char is:" << sizeof(char)<< "Bytes" << endl;
cout << "size of float is:" << sizeof(float)<< "Bytes" << endl;
cout << "size of double is:" << sizeof(double)<< "Bytes" << endl;
cout << "size of bool is:" << sizeof(bool)<< "Bytes" << endl;
return 0 ;
int main()
{ int num;
cout << "Enter a Number"<< endl;
cin >> num;
int cube = num * num * num;
return 0;
}
12, #include <iostream>
int main()
{
float eng,maths,phy,sum,per;
cout << " Enter Marks for english:" <<endl;
cin >> eng;
cout << "Enter marks for Maths:" <<endl;
cin>> maths;
cout << " Enter marks for physics:"<<endl;
cin >> phy;
sum = eng+maths+phy;
cout << "\n Total marks:" << sum;
per = (sum/300)*100;
cout << "\n percentage:" << per << "%" <<endl;
return 0;
}
int main()
{
int age=45;
if(age>18){
cout<<"Eligiable to vote";
}
else{
cout<<"Not Eligible to vote";
}
return 0;
}
LAB MANUAL
14, (Greatest Number)
#include <iostream>
int main()
{
int Num1,Num2,Num3;
cout<<"Enter First Number:";
cin>>Num1;
cout<<"Enter Second Number:";
cin>>Num2;
cout<<"Enter Third Number:";
cin>>Num3;
else{
cout<<"Number 3 is Greatest";
}
return 0;
}
int main()
{
int a,b,temp;
cout<<"Enter first variable:";
cin>>a;
cout<<"Enter Second variable";
cin>>b;
temp=b; //2 step
b=a; //3 step
a=temp;// 4 step
return 0;
}
int main()
{
int year;
cout<<"Enter Leap Year:"<<endl;
cin>>year;
if(year&4==0){
cout<<year<<"It is a leap year.";
}
else{
cout<<"It is no a leap year";
}
return 0;
}
int main()
{
int num1;
cout<<"Enter Number:"<<endl;
cin>>num1;
if(num1>0){
cout<<"Positive Number";
}
else{
cout<<"Negative Number";
}
return 0;
}
MID TASK
int main()
{
int num;
cout<<"Enter Number:"<<endl;
cin>>num;
if(num%2==0){
cout<<"Even Number"<<endl;
}
else{
cout<<"Odd Number"<<endl;
} return 0;
}
#include <iostream>
int main()
{
int num;
cout<<"Enter the Number"<<endl;
cin>>num;
if(num<10 || num>100){
cout<<"The number is either less than 10 or greater than 100"<<endl;
}
else{
cout<<"The number is between 10 and 100"<<endl;
}
return 0;
}
20, (Age is Greater than 60 and You are a Member, and You are Eligible for Discount)
#include <iostream>
int main()
{
int age;
char isMember;
int main()
{
int score;
cout<<"Enter score:"<<endl;
cin>>score;
if(score<0 || score>100){
cout<<"Invalid input.Score should be between 0 to 100"<<endl;
}
else if(score>=90){
cout<<"Grade A";
}
else if(score>=80 && score<90){
cout<<"Grade B";
}
else if(score>=70 && score<80){
cout<<"Grade C";
}
else if(score>=60 && score<70){
cout<<"Grade D";
}
else{
cout<<"Grade F"<<endl;
}
return 0;
}
#include <iostream>
int main()
{
int marks= 50;
if(marks>0 && marks<=100){
if(marks>=90)
cout<<"Grade A"<<endl;
else if (marks>=80)
cout<<"Grade B"<<endl;
else if (marks>=70)
cout<<"Grade C"<<endl;
else
cout<<"Fail!!"<<endl;
}
else{
cout<<"Marks Should be Between 0-100";
}
return 0;
}
#include <iostream>
int main()
{
int marks= 50;
if(marks>0 && marks<=100){
if(marks>=90)
cout<<"Grade A"<<endl;
else if (marks>=80)
cout<<"Grade B"<<endl;
else if (marks>=70)
cout<<"Grade C"<<endl;
else
cout<<"Fail!!"<<endl;
}
else{
cout<<"Marks Should be Between 0-100";
}
return 0;
}
#include <iostream>
int main()
{
for(int i= 1; i<=100; i+=2){
cout<< i << "Odd Numbers" << endl;
}
return 0;
}
#include <iostream>
int main()
{
for(int i= 0; i<=100; i+=2){
cout<< i << "Odd Numbers" << endl;
}
return 0;
}
#include <iostream>
int main()
{
for (int i = 1; i <= 10; i++) {
cout << i << " ";
}
return 0;
}
#include <iostream>
int main()
{
int sum= 0;
for(int i=1; i<=5; i++){
sum+=1;
}
cout<<"Sum of Number's from 1 to 5 is:" << sum<<endl;
return 0;
}
#include <iostream>
int main()
{
int i = 1;
while(i<=15){
cout<< i << " ";
i+=2;
}
return 0;
}
int main()
{
int secretnumber = 6;
int guess;
while(guess != secretnumber){
cout<<"Wrong Guess! Try again:"<<endl;
cin>> guess;
}
cout<< "Congratulates! You guess the secret Number"<<endl;
return 0;
}
#include <iostream>
int main()
{
int secretnumber = 6;
int guess;
while(guess != secretnumber){
cout<<"Wrong Guess! Try again:";
cin>> guess;
}
cout<< "Congratulates! You guess the secret Number"<<endl;
return 0;
}
#include <iostream>
int main()
{
int length,width,area,parameter;
cout<<"Enter Length:"<<endl;
cin>>length;
cout<<"Enter Width:"<<endl;
cin>>width;
area=length*width;
parameter=(2*(length+width));
cout<<"Area of rectangle: "<<area<<endl;
cout<<"parameter of rectangle: "<<parameter<<endl;
return 0;
}
32, (Vowel)
#include <iostream>
int main()
{
char alpha;
cout<<"Enter Vowel"<<endl;
cin>>alpha;
}
else{
cout<<"Its Not Vowel: "<<alpha<<endl;
}
return 0;
}
#include <iostream>
int main()
{
int number;
cout<<"Enter Number"<<endl;
cin>>number;
if(number%2==0){
cout<<"Even Number"<<endl;
}
else{
cout<<"Odd Number"<<endl;
}
return 0;
}
int main()
{
int month;
cout << "Enter month number (1-12): ";
cin >> month;
switch(month) {
case 1:
cout << "January" << endl;
break;
case 2:
cout << "February" << endl;
break;
case 3:
cout << "March" << endl;
break;
case 4:
cout << "April" << endl;
break;
case 5:
cout << "May" << endl;
break;
case 6:
cout << "June" << endl;
break;
case 7:
cout << "July" << endl;
break;
case 8:
cout << "August" << endl;
break;
case 9:
cout << "September" << endl;
break;
case 10:
cout << "October" << endl;
break;
case 11:
cout << "November" << endl;
break;
case 12:
cout << "December" << endl;
break;
default:
cout << "Invalid month number!" << endl;
}
return 0;
}
int main()
{
float num1,num2;
char op;
cout<<"Enter first number"<<endl;
cin>>num1;
cout<<"Enter second number"<<endl;
cin>>num2;
cout<<"Enter operator(+,-,*,/):"<<endl;
cin>>op;
switch(op){
case '+':
cout<<num1+num2<<endl;
break;
case '-':
cout<<num1-num2<<endl;
break;
case '*':
cout<<num1*num2<<endl;
break;
case '/':
cout<<num1/num2<<endl;
break;
default:
cout<<"Matches None"<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
char grade;
cout<<"Enter Grade (A-F): "<<endl;
cin>>grade;
grade=toupper(grade);
switch(grade){
case 'A':
cout<<"Excellent Work! Keep it Up!"<<endl;
break;
case 'B':
cout<<"Great Job You are doing well"<<endl;
break;
case 'C':
cout<<"Good Effort! You can do even better"<<endl;
break;
case 'D':
cout<<"Very Good! Never Leave the Hope"<<endl;
break;
case 'E':
cout<<"Good Try! You can try more"<<endl;
break;
case 'F':
cout<<"Ohh No!! Better luck next time"<<endl;
break;
default:
cout<<"invalid"<<endl;
}
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int choice;
float area;
switch(choice){
case 1:
float radius;
cout<<"Enter radius"<<endl;
cin>>radius;
area=M_PI*radius*radius;
cout<<"Area of circle is: "<<area<<endl;
break;
case 2:
float side;
cout<<"Enter the side length of square: ";
cin>>side;
area = side*side;
cout<<"The area of the square is:" <<area<<endl;
break;
case 3:
float height,base;
cout<<"Enter height: "<<endl;
cin>>height;
cout<<"Enter base: "<<endl;
cin>>base;
area = 0.5* height * base;
cout<<"The Area of the triangle is:"<<area<<endl;
break;
default:
cout<<"invalid input"<<endl;
}
return 0;
}
int main()
{
int num,fact=1;
cout<<"Enter a positive integer:";
cin>>num;
int main() {
int num, i, count = 0;
cout << "Enter a number: ";
cin >> num;
if (num <= 1) {
cout << "Not a prime number." << endl;
}
else if (count == 0) {
cout << "Prime number." << endl;
}
else {
cout << "Not a prime number." << endl;
}
return 0;
}
int main() {
int n, t1 = 0, t2 = 1, nextTerm;
return 0;
}
int main() {
int rows;
cout << "Enter Number of Rows: ";
cin >> rows;
return 0;
}
#include <iostream>
int main()
{
string a[2]={"Hello","BSAI"};
cout<<a[0];
cout<<a[1];
42, Example 2
#include <iostream>
int main()
{
string cars[4]={"Volvo","BMW","Ford","Mazda"};
cars[0]="Audi";
cout<<cars[0];
cout<<cars[1];
return 0;
}
43, Example 3
#include <iostream>
int main()
{
string cars[5]={"Volvo","BMW","Ford","Mazda","Audi"};
for(int i = 0; i < 5; i++){
cout << cars[i]<<"\n";
}
return 0;
}
44, Example 4
#include <iostream>
int main()
{
string cars[5]={"Volvo","BMW","Ford","Mazda","Audi"};
for(int i = 0; i < 5; i++){
cout << i << "="<<cars[i]<<"\n";
}
return 0;
}
45,Example 5
#include <iostream>
int main()
{
int myNumbers[5] = {10,20,30,40,50};
for(int i = 0; i < 5; i++){
cout<<myNumbers[i]<<"\n";
}
return 0;
}
46,Example 6
#include <iostream>
int main()
{
string cars[]={"Volvo","BMW","Ford"};
cout<<cars[0]<<endl;
cout<<cars[1]<<endl;
cout<<cars[2]<<endl;
return 0;
}
47 Example 7
#include <iostream>
int main()
{
int n;
cout<<"Enter Number of array elements:";
cin>>n;
int array[n];
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a[2] = {0,1};
int b[2] = {2,3};
int c[2];
#include <iostream>
using namespace std;
int main() {
int n;
int arr1[n],arr2[n],sum[n];
return 0;
}
int main() {
int number;
char choice;
do {
// Ask the user for the number
cout << "Enter a number to generate its multiplication table: ";
cin >> number;
} while (choice == 'Y' || choice == 'y'); // Continue if user enters 'Y' or 'y'
return 0;
}
int main() {
int num, factorial = 1;
return 0;
}
int main()
{
int arr[3][3]={{1,2,3},{4,5,6},{7,8,9}};
return 0;
}
#include <iostream>
int main()
{
int arr2D[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int arr3D[2][2][3] = {
{{1, 2, 3}, {3, 4, 5}},
{{1, 2, 4}, {3, 4, 5}}
};
return 0;
}
int main() {
int matrix1[2][2];
int matrix2[2][2];
int result[2][2];
return 0;
}
int main()
{
char alpha;
cout<<"Enter Vowel: "<<endl;
cin>>alpha;
}
else{
cout<<"Its Not Vowel: "<<alpha<<endl;
}
return 0;
}
switch(alpha) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
cout << "It's a Vowel: " << alpha << endl;
break;
default:
cout << "It's Not a Vowel: " << alpha << endl;
}
return 0;
}
58,