Posts

Showing posts from April, 2020

Featured post

-Write C program to find even and odd number using macro

-Write C program to find even and odd number using macro #include<stdio.h> #define number(n)((n%2==0)?1:0) int main() { int num; printf("enter any number"); scanf("%d",&num); if(number(num)) printf("number is even"); else printf("number is odd"); return 0; } ***************************Output*********************** amr@amrj-virtual-machine:~$ gccevenodd.c amr@samr-virtual-machine:~$ ./a.out enter any number 2 number is evensmj@amr-virtual-machine:~$

Write a c++ program to find Maximum of Three using parameterized Constructor.

//Maximum number using parameterized constructor  #include<iostream> using namespace std; class temp { int c; public: temp(int a,int b,int c) { if(a>b && b>c) { cout<<"maximum number is :"<<a; } else if(b>c) { cout<<"maximum number is "<<b; } else { cout<<"maximum number is"<<c; } } }; int main() { int a,b,c; cout<<"Enter the value:"; cin>>a>>b>>c; temp obj(a,b,c); return 0; } Out Put ******************************************************************** Enter the value:53 2 1 maximum number is :53 -------------------------------- Process exited after 5.656 seconds with return value 0 Press any key to continue . . . ************************************************************************

Write a C progrming To Calculate & Print Arithmetic Mean and Harmonic Mean.

  Write a C progrming  To Calculate & Print Arithmetic Mean and Harmonic Mean. To Calculate & Print Arithmetic Mean and Harmonic Mean. #include<stdio.h> void main() { floata,b; floatam,hm; printf("Enter the value of a"); scanf("%f",&a); printf("Enter the value of b"); scanf("%f",&b); am=(a+b)/2; printf("arithmetic mean=%f",am); hm=2/(1/a+1/b); printf("\n"); printf("harmonic mean=%f",hm); printf("\n"); } OUTPUT :- Amr@Amr-virtual-machine: ~ $ gcc slip1a.c Amr@Amr-virtual-machine:~$ ./a.out Enter the value of a 120 Enter the value of b 20 arithmeticmean= 70.0000 harmonic mean= 34.285713

Write a C Program to accept an integer and check if it is Even or Odd.

C Program to Check Even or Odd Number 🖥️ C Program to Check Even or Odd Number Below is a simple C program that checks whether a given number is even or odd. 📜 Source Code: #include <stdio.h> void main() { int num; printf("Enter number: "); scanf("%d", &num); if (num % 2 == 0) { printf("Number is even"); } else { printf("Number is odd"); } } 🖥️ Output: amr@amr-virtual-machine:~$ gcc slip6a.c amr@amr-virtual-machine:~$ ./a.out Enter number: 12 Number is even 🔹 Explanation: The program takes an integer input from the user. It checks whether the number is divisible by 2 using the modulus (%) operator. If the remainder is 0, it prints " Number is even ", otherwise, it prints " Number is odd ". 📌 Steps to Compile and Run: Save the file as slip6a.c . Open a terminal and navigate to the file location....