Programming in c
This presentation is the property of its rightful owner.
Sponsored Links
1 / 15

Programming In C++ PowerPoint PPT Presentation


  • 81 Views
  • Uploaded on
  • Presentation posted in: General

Programming In C++. Spring Semester 2013 Practice 2. Practice-1. Write down a program to return sum of square of two numbers entered by the user with the help of a function. Practice-1. #include< stdio.h > #include< conio.h > int sqSum ( int,int ); int main(void) {

Download Presentation

Programming In C++

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Programming in c

Programming In C++

Spring Semester 2013

Practice 2

Programming In C++, Practice By Umer Rana


Programming in c

Practice-1

  • Write down a program to return sum of square of two numbers entered by the user with the help of a function.

Programming In C++, Practice By Umer Rana


Programming in c

Practice-1

#include<stdio.h>

#include<conio.h>

intsqSum(int,int);

int main(void)

{

int num1,num2,Ans;

printf("First Number is ");

scanf("%d",&num1);

printf("\n2nd Number is ");

scanf("%d",&num2);

Ans=sqSum(num1,num2);

printf("\nSum of the Square of two Numbers is %d",Ans);

getch();

}

intsqSum(intp,int q)

{

p=p*p;

q=q*q;

return p+q;

}

Programming In C++, Practice By Umer Rana


Programming in c

Practice-2

  • Write nested loop with help of program?

Programming In C++, Practice By Umer Rana


Programming in c

Practice-2

# include <stdio.h>

# include <cosio.h>

Void main ()

{

int inner, outer;

for(outer=7; outer=>1;outer--)

{

inner=1;

while(inner<+outer)

{

printf(“*”);

inner++

}

printf(“\n”);

}

getche();

}

Programming In C++, Practice By Umer Rana


Programming in c

Practice-3

  • Write down a program using if-else-if statement to find the age group of a student.

Programming In C++, Practice By Umer Rana


Programming in c

Practice-3

int main(void)

{

int Age;

printf("Please Enter the Age of the Student");

scanf("%d",&Age);

if (Age>=18 && Age<=21)

printf("You are in Age Group A");

else if (Age>=22 && Age<=25)

printf("You are in Age Group B");

else if (Age>=26 && Age<=30)

printf("You are in Age Group C");

else if (Age>=31)

printf("You are in Age Group D");

getch();

}

Programming In C++, Practice By Umer Rana


Programming in c

Practice-4

  • Define an array of ten elements to accept a series of numbers from user and then print in descending order.

Programming In C++, Practice By Umer Rana


Programming in c

Practice-4

{

inti,j,temp,a[10];

printf("Enter the numbers \n");

for (i=0; i<10; ++i)

scanf ("%d",&a[i]);

for (i=0; i<10; ++i)

{

for (j=i+1; j<10; ++j)

{ if (a[i] < a[j])

{ temp = a[i];

a[i] = a[j];

a[j] = temp;

}

}

}

printf(“Descending order are given below\n");

for (i=0; i<10; ++i)

printf("%d\n",a[i]);

getche();

}

Programming In C++, Practice By Umer Rana


Programming in c

Practice-5

  • Write down a program using if-else-if statement to calculate two values enter by user and apply chosen function as

    ( + , - , * , / ).

Programming In C++, Practice By Umer Rana


Programming in c

Practice-5

int num1,num2,Ans;

char ope;

printf("Please Enter the two number to operate\n");

scanf("%d",&num1);

scanf("%d",&num2);

printf("\n Please Choose the Function Please (+,-,*,/)\n");

ope=getche();

if(ope=='-')

printf("\nSubtraction of two numbers are %d",num1-num2);

else if(ope=='+')

printf("\nSum of two numbers are %d",num1+num2);

else if(ope=='*')

printf("\n Multiply of two numbers are %d",num1*num2);

else if(ope=='/')

printf("\n Division of two numbers are %d",num1/num2);

getche();

Programming In C++, Practice By Umer Rana


Programming in c

Practice-6

  • Write a program that will print asterisks (*) according to the pattern shown in:

    *********

    *********

    *********

    *********

    *********

Programming In C++, Practice By Umer Rana


Programming in c

Practice-6

int main()

{

for ( int i=0; i<5; i++)

{

for (int j=0; j<=8; j++)

printf("*");

printf("\n");

}

getch();

}

Programming In C++, Practice By Umer Rana


Programming in c

Practice-7

  • Write a program that will print asterisks (*) according to the pattern shown in:

    *

    **

    ***

    ****

    *****

    *****

    ****

    ***

    **

    *

Programming In C++, Practice By Umer Rana


Programming in c

Practice-7

Void main ()

{

for ( int i=0; i<5; i++)

{

for (int j=0; j<=i; j++)

printf("*");

printf("\n");

}

for ( int i=0; i<5; i++)

{

for (int j=4; j>=i; j--)

printf("*");

printf("\n");

}

getch();

}

Programming In C++, Practice By Umer Rana


  • Login