#Include Int Main (Cout "Welcome To C++ Programing" Return )

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Week-1: Assignment-1

Due date: 30th May 2020 – [11:59PM]

Roll no
Name

Complete all the tasks as per the instructions given.

Task-1
=====
Convert all the following C program codes into C++ programming Codes.

Program-1
// A first program in C language.
#include<stdio.h>
#include<conio.h>
void main()
{
printf(“Welcome to C Programming”);
getch();
}
Sample Solution: Program-1

#include<iostream>
Int main()
{
cout << “Welcome to C++ Programing”;
return ;
}

NOTE: conio.h is not required while working in Dev C++. Also calling the clrscr() function
for clearing the screen and getch() function for holding the screen are not required.

Program-2
#include<stdio.h>
void main()
{
int a,b,c;
printf(“Enter the first number : “ );
scanf(“%d”, &a);
printf(“Enter the second number: “);
scanf(“%d”, &b);
c=a+b;
printf(“The sum of numbers is %d” ,c);
}
Program-3
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i;
clrscr();
printf("Enter a number");
scanf("%d",&num);
i=num%2;
if(i==0)
{
printf(“Even number!”);
}
else
{
printf(“Odd number!”);
}
getch();
}

Program-4

#include<stdio.h>
#include<conio.h>
void main()
{
int day;
clrscr();
printf("Enter the days of a week:");
scanf("%d",&day);
switch(day)
{
case 1:
printf("Sunday");
break;
case 2:
printf("Monday");
break;
case 3:
printf("Tuesday");
break;
case 4:
printf("Wednesday");
break;
case 5:
printf("Thursday");
break;
case 6:
printf("Friday");
break;
case 7:
printf("Saturday");
break;
default:
printf("Invalid day number!");
break;
}
getch();
}

Program-5
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=10;i++)
{
printf("%d\n",i);
}
getch();
}

Example-6
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
{
printf("*");
}
printf("\n");
}
getch();
}
Task-2
=====

Write C++ programs for the following questions given. Your answer should also include
output of programs.

1. Write a program to swap value of two variables without using third variable.
2. Write a program which input three numbers and display the largest number using ternary
operator.
3. Write a program which accepts days as integer and display total number of
years, months and days in it.

Task-3
=====

Answer the following questions.

1. What is Object Oriented Programming?


2. Write difference between C language and C++ language.

You might also like