Professional Documents
Culture Documents
Assignment No 4 To 8 (Programing in C)
Assignment No 4 To 8 (Programing in C)
Marks Grade
Marks<40 Fail
Mark>=40 & Pass
mark<60
Mark>=60 & 1st class
mark<75
Mark>=75 & distinction
mark<=100
Algorithm:
Step1: start
Step4: if marks are Marks<40 then display fail else if Mark>=40 & mark<60
Display pass
Else if Mark>=60 & mark<75 display 1st class else if Mark>=75 &
Step 6: stop
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int marks ;
printf("enter your grade");
scanf("%d",&marks);
if( marks<40) {
printf("fail");
}
else if(marks>=40 && marks<60){
printf("pass");
}
Algorithm:
Step1: start
Step4: if marks are Marks<40 then display fail else if Mark>=40 & mark<60
Display pass
Else if Mark>=60 & mark<75 display 1st class else if Mark>=75 &
Step 6: stop
Code:
#include<stdio.h>
#include<conio.h>
void main ()
{
int year;
printf("enter year to check");
scanf("%d",&year);
if(year%400==0){
printf("entered year is leap");
}
else if (year%100==0){
printf("entered year is not leap");
}
else if (year%4==0){
printf("entered year is leap");
}
else{
printf("entered year is not leap");
}
getch();
}
Output :
Assignment No: 6
Algorithm:
Step 1: start
Step2:take input as a, r, sum,x
Flowchart:
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,sum=0,temp;
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf("armstrong number ");
else
printf("not armstrong number");
}
Output:
Assignment No: 7
1 addition
2substraction
3multiplication
4divition
Algorithm:
step1:start
Step2:input a,b,c
Step3:take input for a,b
Step4:use switch for assigning function to perticuler number
As follow 1 for addition 2 for substraction ,3 for multiplication,4 for divition
Step5: print output
Step6:stop:
Flowchart:
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter number");
scanf("%d",&a);
printf("enter number");
scanf("%d",&b);
printf("type 1 to add ,2 to sub ,3 to multiply ,4 to divide");
scanf("%d",&c);
switch(c){
case 1 :
printf("addition of %d and %d is:%d",a,b,a+b );
break ;
case 2 :
printf("subtraction of %d and %d is:%d",a,b,a-b );
break ;
case 3 :
printf("multiplication of %d and %d is:%d",a,b,a*b );
break ;
case 4 :
printf("divition of %d and %d is:%d",a,b,a/b );
break ;
default :
printf("plz enter valid numbeer" );
getch();
}
Output:
Assignment No: 8
Algorithm :
Step 1: Start
Step 2 : Input a
Step 3: Now use switch statement and compare the a with numbers in 1
to 7 As 0 to Sunday, I to Monday, 2 to Tuesday, 3 to Wednesday, 4
Thursday, 5 Saturday.
Step 4: print output
Step 5 : Stop
Code:
#include <stdio.h>
#include <conio.h>
void main()
{
int a;
clrscr();
printf("Enter number ");
scanf("%d",&a);
switch(a){
case 0 :
printf("sunday");
break;
case 1 :
printf("monday");
break;
case 2 :
printf("tuesday");
break;
case 3 :
printf("wednesday");
break;
case 4 :
printf("thursday");
break;
case 5 :
printf("friday");
break;
case 6 :
printf("satarday");
break;
}
getch();
}
Output