0% found this document useful (0 votes)
91 views7 pages

Printf Scanf: "Enter The Number of Prime Numbers Required " "%D"

The code defines functions to calculate the average, highest, and lowest marks from an array of 10 student marks. It prompts the user to enter the marks, calls the functions to calculate the results, and displays the average, highest, and lowest marks along with each student's mark and difference from the average.

Uploaded by

drahcir_425
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views7 pages

Printf Scanf: "Enter The Number of Prime Numbers Required " "%D"

The code defines functions to calculate the average, highest, and lowest marks from an array of 10 student marks. It prompts the user to enter the marks, calls the functions to calculate the results, and displays the average, highest, and lowest marks along with each student's mark and difference from the average.

Uploaded by

drahcir_425
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

#include<stdio.

h>
int main()
{
int n, i = 3, count, c;
printf("Enter the number of prime numbers required\n");
scanf("%d",&n);
if ( n >= 1 )
{
printf("First %d prime numbers are :\n",n);
printf("2\n");
}
for ( count = 2 ; count <= n ; )
{
for ( c = 2 ; c <= i - 1 ; c++ )
{
if ( i%c == 0 )
break;
}
if ( c == i )
{
printf("%d\n",i);
count++;
}
i++;
}
}

return 0;

#include<stdio.h>
main()
{
int n, c = 2;
printf("Enter a number to check if it is prime\n");
scanf("%d",&n);
for ( c = 2 ; c <= n - 1 ; c++ )
{
if ( n%c == 0 )
{
printf("%d is not prime.\n", n);
break;
}
}
if ( c == n )
printf("%d is prime.\n", n);
}

return 0;

#include<stdio.h>
int check_prime(int);
main()
{
int n, result;
printf("Enter an integer to check whether it is prime or not.\n");
scanf("%d",&n);
result = check_prime(n);
if ( result == 1 )
printf("%d is prime.\n", n);
else
printf("%d is not prime.\n", n);
}

return 0;

int check_prime(int a)
{
int c;
for ( c = 2 ; c <= a - 1 ; c++ )
{
if ( a%c == 0 )
return 0;
}
if ( c == a )
return 1;
}

/* C program to check whether a number is prime or not. */


#include <stdio.h>
int main()
{
int n, i, flag=0;
printf("Enter a positive integer: ");
scanf("%d",&n);
for(i=2;i<=n/2;++i)
{
if(n%i==0)
{
flag=1;
break;
}
}

if (flag==0)
printf("%d is a prime number.",n);
else
printf("%d is not a prime number.",n);
return 0;

/* C programming code to check whether a character is alphabet or not.*/


#include <stdio.h>
int main()
{
char c;
printf("Enter a character: ");
scanf("%c",&c);
if( (c>='a'&& c<='z') || (c>='A' && c<='Z'))
printf("%c is an alphabet.",c);
else
printf("%c is not an alphabet.",c);
return 0;
}

C program to entered character is alphabet


or number or special character.
// C program to entered character is alphabet or number or special character.
#include<stdio.h>
void main()
{
char ch;
printf("Please enter an character : ");
scanf("%c", &ch);
if(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'))
{
printf("Entered character %c is a alphabet", ch);
}
if('0' <= ch && ch <= '9')
{
printf("Entered character %c is a number", ch);
}
else
{
printf("Entered character %c is a special character", ch);
}
}

import java.util.*;
public class Gpa
{static Scanner stdIn= new Scanner(System.in);
public static void main (String[]args)
{
char grade1=' ';
char grade2=' ';
double gradevalue1=0;
double gradevalue2=0;
double gpa;
double totalpointscourse1;
double totalpointscourse2;
double credithours1,credithours2;
System.out.print("enter grade for course1 like A,B,C,D,F: ");
grade1=stdIn.next().charAt(0);
System.out.print("enter credit hours for course1: ");
credithours1=stdIn.nextDouble();
System.out.print("enter grade for course2 like A,B,C,D,F: ");
grade2=stdIn.next().charAt(0);
System.out.print("enter credit hours for course2: ");
credithours2=stdIn.nextDouble();
if(grade1=='A')
gradevalue1=4;
else
if(grade1=='B')
gradevalue1=3;
else if (grade1=='C')
gradevalue1=2;
else if (grade1=='D')
gradevalue1=1;
else
gradevalue1=0;

if(grade2=='A')
gradevalue2=4;
else
if (grade2=='B')
gradevalue2=3;
else if (grade2=='C')
gradevalue2=2;
else if (grade2=='D')
gradevalue2=1;
else
gradevalue2=0;
totalpointscourse1=gradevalue1*credithours1;
totalpointscourse2=gradevalue2*credithours2;
gpa= (totalpointscourse1+totalpointscourse2)/(credithours1+credithours2);

if(grade1=='A'||grade1=='B'||grade1=='C'||grade1=='D'||grade1=='F'||
grade2=='A'||grade2=='B'||
grade2=='C'||grade2=='D'||grade2=='F')
System.out.println(" your gpa is" + gpa);
else
System.out.println(" invalid gpa");
if(gpa>=3.5)
System.out.println("Congratulations");
else if (gpa<2.0)
System.out.println("WARNING");
if (grade1>grade2) {
System.out.println(grade2);
System.out.println(grade1);
}
else {
System.out.println(grade1);
System.out.println(grade2);
}
}
}

Code for Program that reads 10 students marks and displays


average, lowest and highest marks in C++ Programming
#include<iostream.h>
#include<conio.h>
float average_marks(float []);
float highest_marks(float []);
float lowest_marks(float []);
main()
{
clrscr();
float marks[10]={0};
cout<<"\n Enter the marks of the ten students : "<<endl;
cout<<"\n\t Student No.
Marks Obtained"<<endl;

for(int count_1=0;count_1<10;count_1++)

cout<<"\t\t"<<count_1+1<<"\t\t";
cin>>marks[count_1];
}
getch();
clrscr();
cout<<"\n ********************

Result Sheet

****************"<<endl;

cout<<"\n Total Marks = 100"<<endl;


cout<<" Average Marks = "<<average_marks(marks)<<endl;
cout<<" Highest Marks obtained = "<<highest_marks(marks)<<endl;
cout<<" Lowest Marks obtained = "<<lowest_marks(marks)<<endl;
cout<<"\n
Status"<<endl;

Student No.

Marks Obtained

Diff. from Average Marks

int y=10;
for(int count_2=0;count_2<10;count_2++)
{
cout<<"\t"<<count_2+1<<"\t\t"<<marks[count_2];
gotoxy(42,y);
cout<<marks[count_2]-average_marks(marks)<<"\t\t
"<<
((marks[count_2]>=50)?"Pass":"Fail")<<endl;
y++;
}

getch();
return 0;

/*************************************************************************///----------------------- average_marks(float [])


--------------------///*******************************************************
******************/float average_marks(float marks[])
{
float sum=0;
for(int count=0;count<10;count++)
sum+=marks[count];
return sum/10;
}
/*************************************************************************///-------------------- highest_marks(float [])
-----------------------///****************************************************
*********************/float highest_marks(float marks[])
{
float highest=marks[0];
for(int count=0;count<10;count++)

{
}

if(marks[count]>highest)
highest=marks[count];
return highest;

}
/*************************************************************************///--------------------- lowest_marks(float [])
-----------------------///****************************************************
*********************/float lowest_marks(float marks[])
{
float lowest=marks[0];
for(int count=0;count<10;count++)

if(marks[count]<lowest)
lowest=marks[count];
}

return lowest;

You might also like