Shared Code

by reddiharipriya12·4 views·Aug 5, 2026Open in Playground →
main.cu
1234567891011121314151617181920212223242526272829303132
#include <iostream>
#include <cuda_runtime.h>
using namespace std;

__global__ void addition(int a, int b, int *c)
{
    *c = a + b;
}

int main()
{
    int a, b;
    int *c;

    cudaMallocManaged(&c, sizeof(int));

    cout << "Enter first number: ";
    cin >> a;

    cout << "Enter second number: ";
    cin >> b;

    addition<<<1,1>>>(a, b, c);

    cudaDeviceSynchronize();

    cout << "Sum = " << *c << endl;

    cudaFree(c);

    return 0;
}

Comments (0)

to post comments and vote
No comments yet. Be the first to share your thoughts!